lately tested with Docker version 17.12.0-ce, build c97c6d6 on Ubuntu artful and Slackware 14.2
you need the Swarm nodes to be able to pull the image from a common repository.
as ceph@admin
I’m having 3 Ceph nodes sharing a common Ceph/FS into /datafs/
. So let’s use ceph2 as Swarm manager and ceph1 and 3 as Swarm workers,
ssh ceph@ceph2 docker swarm init
note. if there are multiple IP addresses configured you get a warning and need to specify on which one you want to advertise the service,
docker swarm init --advertise-addr x.x.x.x
generate the tokens,
#docker swarm join-token manager docker swarm join-token worker ^D
for the (manager or) workers to join the Swarm cluster,
ssh ceph@ceph1 docker swarm join --token x.x.x.x:2377 ^D ssh ceph@ceph3 docker swarm join --token TOKEN x.x.x.x:2377 ^D
Back to the manager node, check the Swarm cluster status,
ssh ceph@ceph2 docker node ls docker node ps docker node ps --no-trunc
--mode=global
to rebalance the instances after a host has recovered,
docker service ls docker service update SERVICE-ID --detach=false --force
to list the running instances and operating hosts,
docker stack ps appname
to remove an application,
docker stack rm appname
for a worker to leave the cluster,
docker swarm leave
for a manager to leave the cluster,
docker swarm leave --force
as ceph@ceph2
mkdir -p ~/compose/weblab/ cd ~/compose/weblab/ vi docker-compose.yml
here’s a basic example,
version: "3" services: web: # replace username/repo:tag with your name and image details image: pbraun9/ubuntu:latest deploy: replicas: 3 resources: limits: cpus: "0.1" memory: 50M restart_policy: condition: on-failure ports: - "8080:8080" networks: - webnet networks: webnet:
and here’s how to create some depedencies – docker host constraints – among the containers.
make sure the folder exists on the docker host,
mkdir /datafs/weblab/ echo ok > /datafs/weblab/test
then in the Compose service stanza (e.g. services / web),
volumes: - /datafs/weblab:/weblab
run the thing,
docker stack deploy -c docker-compose.yml appname
and check,
docker ps docker exec -ti CONTAINER_NAME bash ls -alhF /weblab/
run the webnet
and web
containers and check on all the Swarm nodes at once,
docker stack deploy -c docker-compose.yml lab1 docker stack ps lab1
eventually change the number of replicas to scale the app,
vi docker-compose.yml docker stack deploy -c docker-compose.yml lab1
review the services associated with the app,
docker stack services lab1
remove the containers,
docker stack rm lab1