4 Packaging applications from source code into Docker images
Building Docker images is easy. Earlier, 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 are 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. Now, 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 (e.g., GitHub) where everyone pushes their code changes, as well as typically a separate server (or online service) that 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 will fail on the build server, and the team will be 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 (see figure 4.1 for some examples).