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 ...