Docker multistage build
March 15, 2022The 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
Example
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' services: web: build: 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
Video demonstration and explanation of how docker multistage build works:
Resources
Articles on a similar topic
VMware vs Proxmox: performance comparison
GitLab CI/CD: test automation and application deployment
Migrating VPS from VMware to Proxmox
VMware licensing change
Running Microsoft SQL Server on Linux
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
Backing up your data by turning on your computer
Podman
Importing Windows into Proxmox virtualization
Docker and PHP mail
Proxmox virtualization
Docker and Cron
Lenovo ThinkPad X1 Carbon: LTE modem EM7544 commissioning
Yocto Project: Build custom operating system for embedded devices
Preparing a Linux server to run a web application in Python
How to address poor file share performance in Docker
How to get started using Docker correctly
Installing Linux on a dedicated HPE ProLiant DL320e server
How to stress test a web application
Why use the JFS filesystem
How to boot from a 4TB drive with GTP using UEFI
Btrfs file system
Raspberry PI
WINE - running Windous programs under Linux
GNU/Linux operating system
Newsletter
If you are interested in receiving occasional news by email.
You can register by filling in your email
news subscription.
+