Docker multistage build

March 15, 2022

Lang: cs en de es

The Docker multistage build is a feature that can make it easier to build different Docker images based on the same base. There you can prepare an image for different purposes. And at the same time efficiently prepare images that contain everything you need while being minimalistic.

Multistage build

The principle of multistage build is that you have a common base in one configuration file and then you can create different docker images based on that. This allows you to streamline and simplify the creation of docker images.
Ted docker image for development, for testing, or minimalist for production


In this link. docker multi stage example.
You can use this demonstration project to try it out, and this guide is also written based on it.

This command will execute the build image for the "base" target:

docker build --target base ./

Better, however, to name the image directly

 docker build --target base ./ -t php-web-base

Build image for target devel, which we will name php-web-dev:

docker build --target devel ./ -t php-web-dev

Build containers that are listed in the docker-compose file:

docker-compose -f docker-compose-prod.yml build

The contents of the docker-compose. The important parameter is the target parameter, which specifies what image to build and then run.

version: '3.6'
        context: ./
        target: devel

If you have the container built and named, you can drop the docker image and shell console in as you would with any other docker image:

docker exec -it multistage-build_web_1 /bin/bash


Video demonstration and explanation of how docker multistage build works:


multistage-build documentation

Články na podobné téma

Backup: the Proxmox Backup Server
Linux as a router and firewall
How to upload a docker image to the Docker Registry
Linux: logical volume management
Linux Software RAID
Running a web application behind a proxy
Mailbox migration
Importing Windows into Proxmox virtualization
Docker and PHP mail
Proxmox virtualization
Docker and Cron
How to address poor file share performance in Docker
How to get started using Docker correctly
Raspberry PI
GNU/Linux operating system


If you are interested in receiving occasional news by email.
You can register by filling in your email news subscription.