Deploying and Managing Services at Scale with Docker Swarm
Integrating Traefik with the WordPress Stack
Now, if you want to do the same thing for the WordPress stack that we created in the previous section, you need to adapt your compose file by adding the right labels to the WordPress service.
To start, create the external network that will be used by both Traefik and the WordPress stack:
docker network create --driver overlay --attachable wordpress
Re-deploy Traefik as a front-end load balancer as explained in the previous section.
cd $HOME && mkdir -p traefik && cd traefik && cat < docker-compose.yml && \
docker stack deploy -c docker-compose.yml traefik
services:
reverse-proxy:
image: traefik:v3.6.7
command:
- "--entrypoints.web.address=:80"
- "--api.insecure=true"
- "--providers.swarm=true"
- "--providers.swarm.endpoint=unix:///var/run/docker.sock"
- "--providers.swarm.exposedByDefault=false"
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
labels:
traefik.enable: "False"
placement:
constraints:
- node.role == manager
networks:
- wordpress
networks:
wordpress:
external: true
EOF
Before moving to the second step, create the folder wordpress and add the secrets to it:
cd $HOME && mkdir -p wordpress
# add the secrets
echo "your_db_root_password" > wordpress/.root_password.txt
echo "your_db_wordpress_password" > wordpress/.password.txt
Export MANAGER_NODE_IP to use it in the docker-compose.yml file:
MANAGER_NODE_IP=
Let's see the full docker-compose.yml file:
cd $HOME && cat < wordpress/docker-compose.yml && \
docker stack deploy -c wordpress/docker-compose.yml wordpress
services:
db:
image: mysql:9.6.0
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_root_password
- db_password
networks:
- internal
deploy:
placement:
constraints:
-Painless Docker - 2nd Edition
A Comprehensive Guide to Mastering Docker and its EcosystemEnroll now to unlock all content and receive all future updates for free.
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
