Docker Community Forums

Share and learn in the Docker community.

Docker container restart on reboot doesn't start UI application

I am starting a docker container using ‘docker run’ on Ubuntu 20.04. I have set the ‘–restart’ option to ‘unless-stopped’ for the ‘docker run’ command. The container restarts automatically if it exits, as expected. However, if I reboot the computer, the docker container does restart as expected but a UI application that is part of the container doesn’t start. If I restart the container, the UI application starts as expected. This issue is seen on multiple computers although not on one other computer.

My guess is that there is a race condition and the docker container on reboot starts before the graphics subsystem on the host is fully initialized i.e. the X server. Is there any way to delay the container restart on reboot to wait on the X server? Alternatively, is there a way I can query from within the docker if the X server is running? I have found ways to query this from the host but not from within the docker.

I am not really good at systemd, but I would try to add a new dependency to docker’s systemd service. I can’t tell you how to do that for sure, except that don’t change the original docker.service. Use systemctl edit docker.service which creates a new file so you can add what you want. It doesn’t require a complete copy of the original service.

That’s a good idea. I can try that but I need to figure what exactly the dependency is. I’m not sure if X server shows up as a service or if there is something else to depend on.