Docker stack deploy

Posted: October 4, 2018 in docker

Docker stack is used to deploy containers on docker swarm. Syntax is very similar to docker-compose with some modification.

docker-compose.yml example file


services:
apache_httpd:
image: httpd:latest
deploy:
mode: replicated
replicas: 2
labels:
com.docker.descr: "test description"
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
placement:
constraints:
- node.role == worker
preferences:
- spread: node.labels.zone
resources:
limits:
memory: 50M
reservations:
cpus: '0.10'
update_config:
parallelism: 1
delay: 10s
monitor: 4s

mode: replicated
replicas: 2

create 2 containers

labels: create docker label

placement:
constraints:
- node.role == worker

deploy container on worker

preferences:
- spread: node.labels.zone

deploy services evenly on all nodes with label zone.

resources:
limits:
memory: 50M

Assign 50 MB for each container

deply stack named stack:

docker stack deploy stack -c docker-compose.yml

list stack:

docker stack ps stack
ID                  NAME                       IMAGE               NODE                DESIRED STATE       CURRENT STATE                     ERROR               PORTS
px316bdihumh        stack_apache_httpd.1       httpd:latest        docker              Running             Running less than a second ago
wtkbnp1b2gmb         \_ stack_apache_httpd.1   httpd:latest        docker              Shutdown            Shutdown less than a second ago
9i6sxjt18igr        stack_apache_httpd.2       httpd:latest        docker              Running             Running less than a second ago
zhzz1keqtitc         \_ stack_apache_httpd.2   httpd:latest        docker              Shutdown            Shutdown less than a second ago</pre>
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
8qanlez114d9 stack_apache_httpd replicated 2/2 httpd:latest *:80->80/tcp

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s