Multi-Stage Builds

December 8, 2025 · 507 words · 3 min

This is part of a series of articles describing how the AtSea Shop application was built using enter

This is part of a series of articles describing how the AtSea Shop application was built using enterprise development tools and Docker. In the previous post, I introduced the AtSea application and how I developed a REST application with the Eclipse IDE and Docker. , a Docker feature introduced in Docker 17.06 CE, let you orchestrate a complex build in a single Dockerfile. Before multi-stage build, Docker users would use a script to compile the applications on the host machine, then use Dockerfiles to build the images. The  is the perfect use case for a multi-stage build because: Let’s look at the . The  is an extension of . From within the The first stage of the build uses a Node base image to create a production-ready frontend  directory consisting of static javascript and css files. A Docker best practice is named stages, e.g. This step first makes our image’s working directory at . We copy the contents of the  directory, which includes the ReactJs source and package.json file, to the root of our image’s working directory. Then we use  to install all necessary ’s node dependencies. Finally,  bundles the  using the node dependencies and ReactJs source into a Once this build stage is complete, the builder has an intermediate image named . This temporary image will not show up in your list of images from a To compile the AtSea REST application, we use a maven image and copy the  file, which maven uses to install the dependencies. We copy the source files to the image and run maven again to build the AtSea jar file using the package command. This creates another intermediate image called . Putting it all together, we use a java image to build the final Docker image. The  directory in , created during the first build stage, is copied to the We copy the AtSea jar file to the java image and set  to start the application and set the profile to use a PostgreSQL database. The final image is compact since it only contains the compiled applications in the JDK base image. This step uses  command to copy files from the intermediate images. Multi-stage builds can also use offsets instead of named stages, e.g.  “ Multi-stage builds facilitate the creation of small and significantly more efficient containers since the final image can be free of any build tools. External scripts are no longer needed to orchestrate a build. Instead, an application image is built and started by using A stack is deployed using Docker Cloud now supports multi-stage builds Log into your Docker Cloud account. After your Github account is connected, click on Repositories on the side menu and then click your atsea_app repository. In the Build Configurations form, complete For more information on multi-stage builds read the  and Docker Captain Alexis Ellis’ . To build compact and efficient images watch Abby Fuller’s Dockercon 2017 presentation,  and check out her . Interested