简体   繁体   中英

Why does one of my Docker containers not start automatically on machine boot?

I have two Docker containers, one to run a Jenkins instance, and one to run YouTrack . Their respective starting scripts look like the following:

  • Jenkins: docker run --name jenkins_master --restart on-failure -p 8080:8080 -p 50000:50000 -v /home/ci/jenkins_home/:/var/jenkins_home -d jenkins:latest

  • YouTrack: docker run --name youtrack --restart on-failure -p 8081:80 -v /home/ci/youtrack/data/:/opt/youtrack/data/ -v /home/ci/youtrack/backup/:/opt/youtrack/backup -d uniplug/youtrack

As you can see, nothing special, some port mapping and some -v .

I would like them to start running when I boot up the PC. The Docker documenation says " Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. "

As Docker "restarts" when I boot up my machine, I assumed both containers to run on boot due to --restart on-failure . But only Jenkins starts to run on port 8080, I have to manually start YouTrack when I reboot my machine.

How can I avoid manually starting the container?

When you reeboot your PC, what the docker daemon does is try to stop the running containers. This is like running docker stop on all running container, and this is what happens (taken from here ):

When you issue a docker stop command Docker will first ask nicely for the process to stop and if it doesn't comply within 10 seconds it will forcibly kill it. If you've ever issued a docker stop and had to wait 10 seconds for the command to return you've seen this in action

The docker stop command attempts to stop a running container first by sending a SIGTERM signal to the root process (PID 1) in the container. If the process hasn't exited within the timeout period a SIGKILL signal will be sent.

For your containers, you specified --restart on-failure that means that the docker daemon will restart your containers only if the exit status is > 0 when they exit. My guess about your issue is that your youtrack container correctly reacts to the SIGTERM signal given by the docker daemon and exits cleanly (exit status 0). On the opposite side, the jenkins container does not exit cleanly. For this reason, only the jenkins container restarts on reboot.

To solve this problem you can run the containers with the --restart always flag and the containers will restart in any case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM