I am currently evaluating docker for containerizing our DevOps infrastructure (jenkins, nexus, …) and I am building a prototyp using docker swarm. My current goal is to deploy two services for nexus repository manager and jenkins build server and a third service for a traefik reverse proxy / load balancer to make my other services available for users.
I created a traefik-compose.yml
file for the traefik service like this:
version: "3.7"
services:
proxy:
image: traefik
command: --api --docker --docker.swarmMode --docker.watch
ports:
- 80:80
- 8080:8080
networks:
- devops-net
volumes:
- /var/run/docker.sock:/var/run/docker.sock
configs:
- source: traefik.config
target: /etc/traefik/traefik.toml
deploy:
placement:
constraints:
- node.role == manager
labels:
- "traefik.docker.network=devops-net"
networks:
devops-net:
external: true
configs:
traefik.config:
external: true
To start the service, I use
docker stack deploy --compose-file traefik-compose.yml traefik
Next I use my custom image bm/nexus to create a nexus service. And here my problem starts.
When I start a nexus service with docker service create
my nexus service becomes visible to the traefik dashboard on localhost:8080 and I can access my nexus UI via localhost/nexus.
docker service create --name nexus --publish 8081:8081 --label traefik.port=8081 --label traefik.frontend=nexus --label traefik.frontend.rule=PathPrefix:/nexus --label traefik.backend=nexus --label traefik.docker.network=devops.net --label traefik.enable=true --network devops-net bm/nexus
I only publish port 8081 to check if my nexus service works.
When I start the nexus like this, it works and is visible to traefik dashboard, no matter on which swarm node it is started (I checked that about 100 times).
For better usability I wanted to put that long docker service create
line into a separate nexus-compose.yml
file for a nexus service like this:
version: "3.7"
services:
nexus:
image: bm/nexus
networks:
- devops-net
deploy:
placement:
constraints:
- node.role == worker
labels:
- "traefik.docker.network=devops-net"
- "traefik.enable=true"
- "traefik.port=8081"
- "traefik.frontend=nexus"
- "traefik.frontend.rule=PathPrefix:/nexus"
- "traefik.backend=nexus"
- "traefik.docker.network=devops.net"
networks:
devops-net:
external: true
And I start this service using
docker stack deploy --compose-file nexus-compose.yml nexus
this creates a service nexus_nexus, but it is not visible to the traefik dashboard on localhost:8080 and I can NOT access my nexus UI via localhost/nexus. But if I add the published port 8081:8081
to the nexus-compose.yml
file, I can access my nexus UI via localhost:8081, so the service sems to work.
I would be very happy if someone could help me with this, because I am wasting hours and hours and I don’t find a solution to this. Maybe I understand something wrong.
Here is some additional info that may help:
OS: Debian stretch
Docker version: 18.09.6
Thank you all in advance