Deploying a docker stack to a swarm fails to start some containers - docker

I'm trying to deploy a compose project to a swarm but after I deploy it I have the problem of not all the services start and some of them keep restarting.
I have the following compose file
version: "3.3"
volumes:
jenkins_home:
external: false
driver: local
driver_opts:
type: none
o: 'bind'
device: '/var/jenkins_home'
docker_certs:
external: false
driver: local
driver_opts:
type: none
o: 'bind'
device: '/etc/certs'
services:
docker:
image: docker:dind
restart: unless-stopped
privileged: true
volumes:
- jenkins_home:/var/jenkins_home
- docker_certs:/certs/client
ports:
- "2376:2376"
environment:
DOCKER_TLS_CERTDIR: /certs
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
jenkins:
image: git.example.com:8444/devops/docker-services/jenkins
build:
context: ./
dockerfile: services/jenkins.dockerfile
restart: unless-stopped
depends_on:
- "docker"
volumes:
- jenkins_home:/var/jenkins_home
- docker_certs:/certs/client
ports:
- "636:636"
- "8443:8443"
- "3268:3268"
- "50000:50000"
environment:
DOCKER_HOST: tcp://docker:2376
DOCKER_CERT_PATH: /certs/client
DOCKER_TLS_VERIFY: 1
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
icecc-scheduler:
image: git.example.com:8444/devops/docker-services/icecc-scheduler
build:
context: ./
dockerfile: services/icecc-scheduler.dockerfile
restart: unless-stopped
ports:
- "8765:8765"
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
icecc-daemon:
image: git.example.com:8444/devops/docker-services/icecc-daemon
build:
context: ./
dockerfile: services/icecc-daemon.dockerfile
restart: unless-stopped
ports:
- "8766:8766"
- "10245:10245"
depends_on:
- "icecc-scheduler"
deploy:
mode: global
and a swarm with two nodes docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
i6edk9ny6z38krv6m5738uzwu st12873 Ready Active 20.10.12
phnvvy2139wft9innou0uermq * st12874 Ready Active Leader 20.10.12
I have all the images built and pushed to the docker registry
When I run docker stack deploy -c docker-compose.yml build-farm it says it deploys sucessfully though I then list the services
docker stack services build-farm
ID NAME MODE REPLICAS IMAGE PORTS
4z6w98jmswav build-farm_docker replicated 0/1 docker:dind *:2376->2376/tcp
r7xuq4vgc92i build-farm_icecc-daemon global 0/2 git.example.com:8444/devops/docker-services/icecc-daemon:latest *:8766->8766/tcp, *:10245->10245/tcp
20ukipii7wli build-farm_icecc-scheduler replicated 0/1 git.example.com:8444/devops/docker-services/icecc-scheduler:latest *:8765->8765/tcp
37r4pm7jgku5 build-farm_jenkins replicated 1/1 git.example.com:8444/devops/docker-services/jenkins:latest *:636->636/tcp, *:3268->3268/tcp, *:8443->8443/tcp, *:50000->50000/tcp
The icecc scheduler and daemon never start on and the docker:dind service keeps starting and stopping

Related

Docker stack deploy on GCP cannot access the webpage

I'm trying to use docker swarm and docker stack to deploy my docker-compose file and after I've deployed my stack successfully, I can't access the web page. It just says the response time is too long with the error message "ERR_CONNECTION_TIMED_OUT" I have also opened the TCP and UDP ports 7946, and 4789 as well. Does anyone know what went wrong?
Here's my docker-compose file:
version: "3.3"
services:
mysql:
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: dbRoot
MYSQL_DATABASE: cloud
MYSQL_USER: php
MYSQL_PASSWORD: php
networks:
- mynet
myphp:
image: php:7.4-apache
depends_on:
- mysql
ports:
- "9000:9000"
volumes:
- ./src:/var/www/html
deploy:
placement:
constraints:
- node.role == manager
networks:
- mynet
mynginx:
image: nginx:latest
depends_on:
- myphp
ports:
- "80:80"
deploy:
mode: replicated
replicas: 2
placement:
constraints:
- node.role == manager
networks:
- mynet
visualizer:
image: dockersamples/visualizer:latest
ports:
- "8080:80"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
phpMyAdmin:
image: phpmyadmin
environment:
PMA_HOST: mysql
ports:
- "8082:80"
networks:
- mynet
volumes:
src:
networks:
mynet:
driver: overlay
ID NAME MODE REPLICAS IMAGE PORTS
9ef6kj1wois8 test_mysql replicated 1/1 mariadb:latest
jjcmp9lrr35f test_mynginx replicated 2/2 nginx:latest *:80->80/tcp
oogi9emcjo0j test_myphp replicated 1/1 php:7.4-apache *:9000->9000/tcp
re8wnkvcxgo2 test_visualizer replicated 0/1 dockersamples/visualizer:latest *:8080->80/tcp
y9i19mxjp69q test_phpMyAdmin replicated 1/1 phpmyadmin:latest *:8082->80/tcp
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
c7b6bv6qgqbn test_visualizer.1 dockersamples/visualizer:latest manager Running Starting 11 seconds ago
xu9cvjjp4xqt test_mynginx.1 nginx:latest manager Running Running 10 seconds ago
klf8nimlljbp test_myphp.1 php:7.4-apache manager Running Running 10 seconds ago
0epkhwsmub8c test_mysql.1 mariadb:latest w1 Running Running 14 seconds ago
zlluox3ga6fw test_phpMyAdmin.1 phpmyadmin:latest manager Running Running 12 seconds ago
knmvjwmcslsj test_mynginx.2 nginx:latest manager Running Running 10 seconds ago

Running Services on Specific Nodes with Docker Swarm

I'm new to docker swarm and looking to set containers to run on a specific node in the swarm.
For example, I have the following nodes:
Manager
Worker1
Worker2
And I have a couple services listed in a compose yml similar to:
services:
my_service:
image: my_image
container_name: my_container_name
networks:
- my_network
my_service2:
image: my_image2
container_name: my_container_name2
networks:
- my_network
How can I make it so that my_service only runs on Worker1 and my_service2 only runs on Worker2?
UPDATE:
I managed to find the solution. Can specify deployment constraints as shown below.
my_service:
image: my_image
container_name: my_container_name
networks:
- my_network
deploy:
placement:
constraints:
- node.hostname == Worker1
my_service2:
image: my_image2
container_name: my_container_name2
networks:
- my_network
deploy:
placement:
constraints:
- node.hostname == Worker2

Docker stack deploy doesn't start services or deploy correctly

I have this compose file
version: "3.3"
volumes:
jenkins_home:
external: false
driver: local
driver_opts:
type: none
o: 'bind'
device: '/var/jenkins_home'
certs:
external: false
driver: local
driver_opts:
type: none
o: 'bind'
device: '/etc/certs'
services:
docker:
image: docker:dind
restart: unless-stopped
privileged: true
volumes:
- jenkins_home:/var/jenkins_home
- certs:/certs/client
ports:
- "2376:2376"
environment:
DOCKER_TLS_CERTDIR: /certs
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
jenkins:
image: git.example.com:8444/devops/docker-services/jenkins
build:
context: services/jenkins
args:
ssl_pass: changeit
restart: unless-stopped
depends_on:
- "docker"
volumes:
- jenkins_home:/var/jenkins_home
- certs:/certs/client
ports:
- "8080:8080"
- "8443:8443"
- "3268:3268"
- "50000:50000"
environment:
DOCKER_HOST: tcp://docker:2376
DOCKER_CERT_PATH: /certs/client
DOCKER_TLS_VERIFY: 1
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
icecc-scheduler:
image: git.example.com:8444/devops/docker-services/icecc-scheduler
build: services/icecc-scheduler
restart: unless-stopped
network_mode: host
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
icecc-daemon:
image: git.example.com:8444/devops/docker-services/icecc-daemon
build: services/icecc-daemon
restart: unless-stopped
network_mode: host
deploy:
mode: global
when I run docker stack deploy --compose-file docker-compose.yml build_farm
It claims to start everything successfully. But running docker stack services build_farm I get
ID NAME MODE REPLICAS IMAGE PORTS
tap0zlw086wm build_farm_docker replicated 0/1 docker:dind *:2376->2376/tcp
n13pcmy8zpip build_farm_icecc-daemon global 0/1 git.example.com:8444/devops/docker-services/icecc-daemon:latest
ofpsosrhrzoq build_farm_icecc-scheduler replicated 0/1 git.example.com:8444/devops/docker-services/icecc-scheduler:latest
b9llhoe97vwz build_farm_jenkins replicated 0/1 git.example.com:8444/devops/docker-services/jenkins:latest *:3268->3268/tcp, *:8080->8080/tcp, *:8443->8443/tcp, *:50000->50000/tcp
Which seems to mean none of the services actually started, I can't access any of them which seems to confirm this.
The second issue is that the icecc-daemon container only has one replica despite being started in global mode with 2 nodes on the swarm
docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
rc6aajdnwnis4dvn4um7qcwk9 ex12873 Ready Active 20.10.12
phnvvy2139wft9innou0uermq * ex12874 Ready Active Leader 20.10.12

Deploy Gitlab Runner stack with docker swarm

I'm trying to deploy a gitlab runner stack in docker-compose above:
version: '3.8'
services:
dind:
image: docker:stable
deploy:
mode: replicated
placement:
constraints:
- "node.role==worker"
restart_policy:
condition: any
volumes:
- /var/lib/docker
command:
- --storage-driver=overlay2
networks:
- netrunner
runner:
image: gitlab/gitlab-runner:alpine
deploy:
mode: replicated
placement:
constraints:
- "node.role==worker"
restart_policy:
condition: any
volumes:
- ./gitlab/runner:/etc/gitlab-runner:Z
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DOCKER_HOST=tcp://dind:2375
depends_on:
- dind
networks:
- netrunner
register-runner:
image: gitlab/gitlab-runner:alpine
deploy:
mode: replicated
placement:
constraints:
- "node.role==worker"
restart_policy:
condition: none
volumes:
- ./gitlab/runner:/etc/gitlab-runner:Z
command:
- register
- --non-interactive
- --locked=false
- --name=Docker Runner
- --executor=docker
- --docker-image=docker:stable
- --docker-volumes=/var/run/docker.sock:/var/run/docker.sock
environment:
- CI_SERVER_URL=https://gitlab.com/
- REGISTRATION_TOKEN=xxxxxxxxxxxxxx
networks:
- netrunner
networks:
netrunner:
driver: overlay
driver_opts:
foo: "1"
Then, with docker swarm initialized, I try the deployment with this pattern:
docker stack deploy --compose-file docker-compose.yml ci
After that, when I check services I get this:
$ docker stack services ci
ID NAME MODE REPLICAS IMAGE PORTS
8ahvxamblhmc ci_dind replicated 0/1 docker:stable
fli2u5wszrvp ci_register-runner replicated 0/1 gitlab/gitlab-runner:alpine
zftmedknrwma ci_runner replicated 0/1 gitlab/gitlab-runner:alpine
I'm testing all the steps in docker playground using one manager and three workers. I have tried lots of variation of the compose.yml above. That one is the closest to correct, in my opinion.
Replicas are not running. What should I do ?

docker stack deploy with mongo volume

i'm starting my docker stack with command:
docker stack deploy --with-registry-auth -c docker-compose.yml app
my docker-compose.yml contains entry for mongo:
mongodb:
image: mongo:3.6
volumes:
- mongodb:/var/lib/mongodb
ports:
- 27017:27017
networks:
- backend
environment:
- AUTH=yes
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "5"
deploy:
replicas: 1
placement:
constraints: [node.hostname == hostname]
networks:
frontend:
backend:
volumes:
mongodb:
im stoping docker stack with docker stack rm app Why i'm losing data in mongo after second start with same command docker stack deploy --with-registry-auth -c docker-compose.yml app ? How to avoid id?
Thanks, smola
ok, i've found answer..
based on image:mongo:3.6 Dockerfile, there are already specified two
volumes: VOLUME /data/db /data/configdb
so in docker-compose.yml need to mount host directories into that volumes:
mongodb:
image: mongo:3.6
volumes:
- /sampledir/db:/data/db <-----
- /sampledir/configdb:/data/configdb <-----
ports:
- 127.0.0.1:27017:27017
networks:
- backend
environment:
- AUTH=yes
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "5"
deploy:
replicas: 1
placement:
constraints: [node.hostname == hostname]

Resources