I trying to deploy docker stack, that includes my development environment. But in random cases I have next error:
> failed to create service < service_name >: Cannot connect to the
> Docker daemon at unix:///var/run/docker.sock. Is the docker daemon
> running?
Next I restart docker daemon. Sometimes it requires to kill docker processes and shims. I deleting old stack and build again. Some times docker successfully finishes build, but socket crashes on the starting stage.
Also all containers work properly when I starting it in regular mode, without swarm or stack. It is not work exactly inside swarm.
I have used next command to build:
> $ docker stack deploy dev-env-stc -c docker-compose.yml
Environment run in Antergos Linux(Arch).
Layout is like at the diagram
Nginx container and docker networks created using commands:
>$ docker run --detach --name nginx-main --net dev-env-ext --ip 10.20.20.10 --publish 80:80 --publish 443:443 --volume /env-vol/nginx/conf:/etc/nginx:ro --volume /env-vol/nginx/www:/usr/var/www --volume /env-vol/nginx/logs:/usr/var/logs --volume /env-vol/nginx/run:/usr/var/run --volume /env-vol/ssl:/usr/var/ssl:ro nginx-webserver
>
> $ docker network create --driver=bridge --attachable --ipv6 --subnet fd19:eb5a:3d2f:f15d::/48 --subnet 10.20.20.0/24 --gateway 10.20.20.1 dev-env-ext
>
> $ docker network create --driver=bridge --attachable --ipv6 --subnet fd19:eb5a:3e30:f15d::/48 --subnet 10.20.30.0/24 --gateway 10.20.30.1 dev-env-int
>
> $ docker network create --driver=overlay --attachable --ipv6 --subnet fd19:eb5a:3c1e:f15d::/48 --subnet 10.20.40.0/24 --gateway 10.20.40.1 dev-env-swarm
>
> $ docker network connect dev-env-swarm --ip=10.20.40.10 nginx-main
>
> $ docker network connect dev-env-int --ip=10.20.30.10 nginx-main
My docker-compose.yml file:
version: '3.6'
volumes:
postgres-data:
driver: local
redis-data:
driver: local
networks:
dev-env-swarm:
external: true
services:
gitlab:
image: gitlab/gitlab-ce:latest
hostname: gitlab.testenv.top
external_links:
- nginx-main
ports:
- 22:22
healthcheck:
test: ["CMD", "curl", "-f", "https://localhost:443"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 60s
deploy:
mode: global
endpoint_mode: vip
resources:
limits:
cpus: "0.50"
memory: 4096M
reservations:
cpus: "0.10"
memory: 512M
restart_policy:
condition: on-failure
delay: 20s
max_attempts: 3
window: 300s
networks:
dev-env-swarm:
aliases:
- gitlab.testenv.top
dns:
- 10.10.10.10
- 8.8.8.8
volumes:
- /env-vol/gitlab/config:/etc/gitlab
- /env-vol/gitlab/logs:/var/log/gitlab
- /env-vol/gitlab/data:/var/opt/gitlab
external_links:
- nginx-main
redis:
env_file: .env
image: redis:3.2.6-alpine
hostname: redis.testenv.top
external_links:
- nginx-main
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:6379"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 60s
deploy:
mode: global
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.20"
memory: 1024M
reservations:
cpus: "0.05"
memory: 128M
restart_policy:
condition: on-failure
delay: 20s
max_attempts: 3
window: 60s
volumes:
- redis-data:/var/lib/redis
command: redis-server --appendonly yes
networks:
dev-env-swarm:
aliases:
- redis.testenv.top
dns:
- 10.10.10.10
- 8.8.8.8
redisco:
image: rediscommander/redis-commander:latest
hostname: redisco.testenv.top
external_links:
- nginx-main
depends_on:
- redis
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8081"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 60s
deploy:
mode: global
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.20"
memory: 512M
reservations:
cpus: "0.05"
memory: 256M
restart_policy:
condition: on-failure
delay: 20s
max_attempts: 3
window: 60s
networks:
dev-env-swarm:
aliases:
- redisco.testenv.top
dns:
- 10.10.10.10
- 8.8.8.8
environment:
REDIS_PORT: 6379
REDIS_HOST: redis.testenv.top
plantuml:
image: plantuml/plantuml-server:tomcat
hostname: plantuml.testenv.top
external_links:
- nginx-main
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 60s
deploy:
mode: global
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.20"
memory: 1024M
reservations:
cpus: "0.05"
memory: 256M
restart_policy:
condition: on-failure
delay: 20s
max_attempts: 3
window: 60s
networks:
dev-env-swarm:
aliases:
- plantuml.testenv.top
dns:
- 10.10.10.10
- 8.8.8.8
portainer-agent:
image: portainer/agent
external_links:
- nginx-main
expose:
- 9001
deploy:
mode: global
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.20"
memory: 1024M
reservations:
cpus: "0.05"
memory: 256M
restart_policy:
condition: on-failure
delay: 20s
max_attempts: 3
window: 60s
environment:
AGENT_CLUSTER_ADDR: tasks.portainer-agent
AGENT_PORT: 9001
LOG_LEVEL: debug
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
dev-env-swarm:
aliases:
- portainer-agent.testenv.top
deploy:
mode: global
portainer:
image: portainer/portainer
command: -H tcp://tasks.portainer-agent:9001 --tlsskipverify
depends_on:
- portainer-agent
external_links:
- nginx-main
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 60s
deploy:
mode: global
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.20"
memory: 2024M
reservations:
cpus: "0.05"
memory: 512M
restart_policy:
condition: on-failure
delay: 20s
max_attempts: 3
window: 60s
volumes:
- /env-vol/portainer/data:/data
hostname: portainer.testenv.top
networks:
dev-env-swarm:
aliases:
- portainer.testenv.top
dns:
- 10.10.10.10
- 8.8.8.8
pgadmin4:
image: dpage/pgadmin4:latest
hostname: pgadmin.testenv.top
external_links:
- nginx-main
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 60s
deploy:
mode: global
endpoint_mode: dnsrr
resources:
limits:
cpus: "0.20"
memory: 1024M
reservations:
cpus: "0.05"
memory: 256M
restart_policy:
condition: on-failure
delay: 20s
max_attempts: 3
window: 60s
environment:
PGADMIN_DEFAULT_EMAIL: email#example.com
PGADMIN_DEFAULT_PASSWORD: PASWORD
networks:
dev-env-swarm:
aliases:
- pgadmin.testenv.top
dns:
- 10.10.10.10
- 8.8.8.8
volumes:
- /env-vol/pgadmin:/var/lib/pgadmin
Problem with socket was from wrong Python installation from sources and manual installation of libs. Looks like I have installed incompatible versions. When I have reinstalled Python from repository this problem wasn't appear again.
Related
Why does Meilisearch service down after few seconds ? Giving error 137 (out of memory - docker doc.)
Inside meili data.ms have 44.000 item and one index.
This is content for meilisearch service :
meilisearch:
container_name: meilisearch
image: 'getmeili/meilisearch:latest'
ports:
- '7700:7700'
volumes:
- './Docker/meilisearch/volume/:/meili_data'
networks:
customnetwork:
ipv4_address: 172.20.0.13
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--spider", "5"]
retries: 3
timeout: 5s
deploy:
resources:
limits:
memory: 6g
reservations:
memory: 5g
So i have deploy my stack application and everything is working as expected. Three container replicas running. Now i access phpmyadmin and try to login to the mysql but i got the error: mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
Both the phpmyadmin and mysql container are on the same network.
version: "3.9"
service:
db:
image: mysql
#container_name: mysql_db
command: --default-authentication-plugin=mysql_native_password
restart: always
secrets:
- mysql_root_password
- mysql_database
- mysql_user
- mysql_password
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password
MYSQL_DATABASE_FILE: /run/secrets/mysql_database
MYSQL_USER_FILE: /run/secrets/mysql_user
MYSQL_PASSWORD_FILE: /run/secrets/mysql_password
ports:
- "9906:3306"
networks:
- back-tier
volumes:
- alpine-db_backup:/var/lib/mysql
- alpine-mysql_logs:/var/log/mysql
- alpine-mysql_cnf:/etc/mysql
deploy:
replicas: 3
placement:
constraints: [node.role == manager]
resources:
reservations:
memory: 128M
limits:
memory: 256M
restart_policy:
condition: on-failure
delay: 30s
max_attempts: 10
window: 60s
update_config:
parallelism: 1
delay: 10s
max_failure_ratio: 0.3
phpmyadmin:
image: phpmyadmin
#container_name: phpmyadmin
ports:
- 8080:80
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
depends_on:
- db
networks:
- back-tier
- front-tier
deploy:
replicas: 2
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M
restart_policy:
condition: on-failure
delay: 30s
max_attempts: 10
networks:
front-tier:
driver: overlay
back-tier:
driver: overlay
For containers on the same network, to get another service's name resolved, you should use its name without the stack name as prefix. So, your PMA_HOST should be db, not titanfxbmp_db.
version: "3.9"
services:
db:
image: mysql
...
phpmyadmin:
image: phpmyadmin
...
environment:
PMA_HOST: db
PMA_PORT: 3306
version: '3.7'
services:
db:
image: "mysql:5.7"
healthcheck:
test: ["CMD-SHELL", 'mysqladmin ping']
interval: 10s
timeout: 5s
retries: 10
ports:
- target: 3306
published: 3306
protocol: tcp
mode: host
deploy:
endpoint_mode: dnsrr
mode: "replicated"
replicas: 2
resources:
limits:
memory: 2G
volumes:
- foo:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/my_file_secret
secrets:
- my_file_secret
secrets:
my_file_secret:
file: ./my_file_secret.txt
volumes:
foo:
driver: local
My docker-compose.yml is as follow:
version: "3"
services:
write:
image: apachegeode/geode:1.11.0
container_name: write
hostname: a.b.net
expose:
- "8080"
- "10334"
- "40404"
- "1099"
- "7070"
ports:
- "10220:10334"
volumes:
- ./scripts/:/scripts/
command: /scripts/sleep.sh gfsh start locator ...
networks:
my-network:
deploy:
replicas: 1
resources:
limits:
cpus: '0.50'
memory: 512M
reservations:
cpus: '0.50'
memory: 512M
restart_policy:
condition: on-failure
depends_on:
- read
read:
image: apachegeode/geode:1.11.0
container_name: read
hostname: a.b.net
expose:
- "8080"
- "10334"
- "40404"
- "1099"
- "7070"
ports:
- "10221:10334"
volumes:
- ./scripts/:/scripts/
command: /scripts/sleep.sh gfsh start locator ...
networks:
my-network:
deploy:
replicas: 1
resources:
limits:
cpus: '0.50'
memory: 512M
reservations:
cpus: '0.50'
memory: 512M
restart_policy:
condition: on-failure
networks:
my-network:
container_name has to be "write" and "read" since they are unique containers but running on the host machine. Setting hostname: a.b.net in the docker-compose.yml sets 192.168.160.2 a.b.net a in /etc/hosts file but /etc/hostname show a which is only the alias name . How can I set /etc/hostname with a.b.net using docker-compose.yml ? I use
docker-compose -f my-docker-compose.yml up -d
to run the containers.
I'm tring to add sticky session on Docker Swarm and I first started to deploy the backend and the traefik containers, but the traefik dashboard isn't showing any providers
loadbalancer:
image: registry.fif.tech/traefik:latest
command: --docker \
--docker.swarmmode \
--docker.watch \
--docker.exposedbydefault=false \
--web \
--entryPoints="Name:http Address::8001" \
--defaultentrypoints="http" \
--checknewversion=false \
--loglevel=DEBUG
ports:
- 8001:8001
- 9090:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /dev/null:/traefik.toml
deploy:
restart_policy:
condition: any
mode: replicated
replicas: 1
update_config:
delay: 2s
placement:
constraints: [node.role == manager]
networks:
- omni-net
web-desktop:
image: 'registry.fif.tech/omnichannel2-webdesktop:${TAG}'
command: dockerize -wait http://172.17.0.1:4001/ora-cmm-workflow-executor/PreProcessService?wsdl catalina.sh run
restart: always
deploy:
mode: replicated
replicas: 2
update_config:
parallelism: 1
delay: 10s
failure_action: continue
order: start-first
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
ports:
- '9999:8080'
environment:
- TZ='${TZ}'
extra_hosts:
- "webdesktop:127.0.0.1"
- "cmm-server-jms:${CMM_JMS_SERVER_IP}"
- "techlog-server-jms:${TECHLOG_JMS_SERVER_IP}"
depends_on:
- "workflow"
- "redis-server"
secrets:
- DBMetadata
- DBSecuencial
- Desktop
- DesktopRedis
- DesktopKey
volumes:
- /logs-pool/tomcat:/cyberbank/logs
configs:
- source: recaptcha_config
target: /cyberbank/ebanking/v2/config/recaptcha.properties
logging:
driver: none
healthcheck:
test: ["CMD-SHELL", "curl --silent --fail http://localhost:8080/Techbank/sso || exit 1"]
interval: 30s
timeout: 2s
retries: 26
start_period: 2m
labels:
- "traefik.enable=true"
- "traefik.docker.network=omnichannel2_omni-net"
- "traefik.port=9999"
- "traefik.frontend.rule=PathPrefix:/Techbank;"
- "traefik.backend.loadbalancer.sticky=true"
networks:
- omni-net
There is any problem on the stack definition?
In swarm mode the traefik labels must be declared on the service instead of the container, so move your labels to the deploy section.
https://docs.docker.com/compose/compose-file/#labels-1