dockerfile

Reduce Docker Image Size by Using Multi-stage Builds

Ggicci
If you don’t take any optimization measures, docker images can easily get large. And in most cases we just wrapped too many inessential things into the images. So, we should take actions to get rid of it. Let’s take a look at a common example Dockerfile for building an application written in Go. FROMgolang:1.10.2-stretch WORKDIR/go/src/github.com/ggicci/docker-example-server COPY . . RUN go install LABEL \ me.ggicci.appdemo.image.created="2006-01-02T15:04:05+08:00" \ me.ggicci.appdemo.image.version="1.0.0" # (and more) WORKDIR/app ENTRYPOINT [ "docker-example-server" ] EXPOSE8080 After building the image by running command docker build -t example:1.