Test Multi-stage-build Feature in Docker Playground

mingderwang
Kubernetes Playground
2 min readSep 23, 2017

Docker Playground provides Docker 17.07 version. New enough to test any new features

Let’s test a new feature called, multi stage build, starting from 17.05.

Example codes from a http://qiita.com blog introduces this new feature as follows,

We can edit a Dockerfile as follow;

FROM  golang:alpine AS build-env
ADD . /work
WORKDIR /work
RUN go build -o hello main.go

FROM busybox
COPY --from=build-env /work/hello /usr/local/bin/hello
ENTRYPOINT ["/usr/local/bin/hello"]

And create a hello world code in glang as follow;

main.go

package main

import "fmt"

func main() {
fmt.Println("Hello World!")
}

Then, just run following command in a docker engine, for example in the docker playground. Screenshot as follow;

docker build -t ming/multistage .

We can exec the program with docker run, and see the output in docker logs.

docker run -d ming/multistage

What we did this for? Actually, we only need to keep busybox running, we don’t need the golang environment after the code is compiled.

So, you can see that busybox image is only 1.13MB, ming/multistage image is just 2.99MB, we don’t need golang image (270MB) in our app image.

Having fun!, next episode will show you how to create a docker swarm in docker playground.

--

--