Separating build and deployment images

Another source of unnecessary files in Docker images is build time dependencies. Source libraries, such as compilers and source header files, are only necessary when building an application inside a Docker image. Once the application is built, these files are no longer necessary, as only the compiled binary and related shared libraries are needed to run the application.

To see an example of this, let's build the following application that is now ready to be deployed to a Docker host that we prepared in the cloud. The following source tree is a simple web application written in Go:

$ tree.├── Dockerfile├── README.md└── hello.go0 directories, 3 files

The following is the content of hello.go describing ...

Get Docker High Performance - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.