What’s new in Docker Compose v3
In this blog, we’ll discuss new features added in Docker Compose v3. Docker compose added the feature of stack deployment with swarm.
To achieve this, we need to create a file named, docker-stack.yml and specify the deploy key, which would allow you to specify various properties of a swarm deployment in docker-stack.yml file.
For deploying this, you simply need to run the
docker-stack deploy command with this
docker-stack.yml file to pull the referenced images and launch the services in a swarm as configured in the
deploy key allows you to specify configuration related to the deployment and running of services. The
deploy key can also be used to constrain some services to run only on the manager node.
Specify configuration related to the deployment and running of services. This only takes effect when deploying to a swarm cluster with `docker stack deploy` command and is ignored by
docker-compose up and
docker-compose run commands.
Several sub-options available are mentioned below:
mode is specified either as
global (exactly one container per swarm node) or
replicated (a specified number of containers). Default is
To specify the number of containers that should be running at any given time.
To specify the placement constraints.
- node.role == manager
- engine.labels.operatingsystem == ubuntu 16.04
To configure how the service should be updated. Useful for configuring rolling updates.
parallelism: The number of containers to update at a time.
delay: The time to wait between updating a group of containers.
failure_action: What to do if an update fails. Either
To configure resource constraints. This replaces the older resource constraint options in Compose files prior to version 3 (
To configure whether and how to restart containers when they exit.
condition: One of
any. Default is any.
delay: How long to wait between restart attempts. Default is 0.
max_attempts: How many times to attempt to restart a container before giving up. Default is never give up.
window: How long to wait before deciding if a restart has succeeded. Default is decide immediately.
To specify labels for the service. These labels will be set only on the service, and not on any containers for the service.
com.example.description: "This label will appear on the web service"
To set labels on containers instead, use the
labels key outside of
com.example.description: "This label will appear on all containers for the web service"
“docker stack deploy” command
docker stack deploy command (supported only by compose v3) is used to deploy with
This command does not support the
build key supported in Compose files, which builds based on a Dockerfile. You need to use pre-built images with
docker stack deploy.
Source: ~ Docker Docs
Disclaimer: Content and image source has been mentioned. Special Credit to concerned folks.