4 Packaging applications from source code into Docker Images
Building Docker images is easy. In Chapter 3 you learned that you just need a few instructions in a Dockerfile to package an application to run in a container. There’s one other thing you need to know to package your own applications – you can also run commands inside Dockerfiles. Commands execute during the build, and any filesystem changes from the command get saved in the image layer. That makes Dockerfiles about the most flexible packaging format there is; you can expand Zip files, run Windows installers and do pretty much anything else. In this chapter you’ll use that flexibility to package applications from source code.
4.1 Who needs a build server when you have a Dockerfile?
Building software on your laptop is something you do for local development, but when you’re working in a team there’s a more rigorous delivery process. There’s a shared source control system like GitHub where everyone pushes their code changes, and typically a separate server (or online service) which builds the software when changes get pushed.
That process exists to catch problems early. If a developer forgets to add a file when they push code, the build fails on the build server and the team gets alerted. It keeps the project healthy, but the cost is having to maintain a build server. Most programming languages need a lot of tools to build projects – figure 4.1 shows some examples.