...

/

What More Can I Learn?

What More Can I Learn?

Learn what more you can do to improve your Docker expertise.

More topics are listed here that you can discover for enhancing your app.

Multi-stage builds

Large Docker images are slower to push and pull. As you become more experienced with Docker, you will want to find ways to make your images. Since version 17.05, Docker has had a feature called multi-stage builds. This lets you use multiple FROM statements in a single Dockerfile. Each new FROM is considered a new stage, and starts as a fresh new image. However, the COPY instruction has been enhanced to let you copy files from earlier stages.

The most obvious use case is where you need a lot of development tools that produce a final artifact. Think of a static site generator like Jekyll or Middleman. You need various tools to develop and generate the site, but once the static files are generated, they are the only thing needed to run the site. Multi-stage builds let you create an initial stage that generates the site, and a separate, final stage that copies those files into a clean web server image. The same goes for compiled languages like Go where, typically, the only thing you need to include in your final image is the compiled binary.

In the case of our Rails app, a quick win could be copying the precompiled assets into a final image, avoiding the need for all the JavaScript dependencies. There are ...