Jenkins service in Docker swarm stays at 0/1 repli

2019-05-21 19:09发布

I'm trying to run a fault tolerant Jenkins in a docker swarm using the following command:

docker service create --replicas 1 --name jenkins -p 8080:8080 -p 50000:50000 --mount src=/home/ubuntu/jenkins_home,dst=/var/jenkins_home jenkins:alpine

But checking the service status and containers running I see that the replicas stay in 0.

ubuntu@ip-172-30-3-81:~$ docker service create --replicas 1 --name jenkins -p 8080:8080 -p 50000:50000 --mount src=/home/ubuntu/jenkins_home,dst=/var/jenkins_home jenkins:alpine
14kwt6xoxorn62irnv9y2wm3r
ubuntu@ip-172-30-3-81:~$ docker service ls
ID            NAME        REPLICAS  IMAGE           COMMAND
14kwt6xoxorn  jenkins     0/1       jenkins:alpine  
87ovyhkparou  helloworld  1/1       alpine          ping docker.com
ubuntu@ip-172-30-3-81:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES
739f8180c989        alpine:latest       "ping docker.com"        21 minutes ago      Up 21 minutes                                     helloworld.1.4rz08cygb7whjmzm3922h0bfb

I've tried running Jenkins in a container (without swarm) and it works perfectly, and also the swarm service example from docker's tutorial also works perfectly.

What is preventing the Jenkins service from running?

1条回答
Fickle 薄情
2楼-- · 2019-05-21 19:25

The problem was with the parameters passed to the --mount option.

I was trying to pass the source as a host directory, when I should be passing a docker volume according to docker swarm documentation. To correct the problem I did the following.

docker volume create --name jenkins_home 

docker service create --replicas 1 --name jenkins -p 8080:8080 -p 50000:50000 --mount source=jenkins_home,dst=/var/jenkins_home jenkins:alpine

As a side-note, I think it would be useful for docker to show an error message when a mount source could not be found.

查看更多
登录 后发表回答