Keep docker container running after logout

Viewed 1937

Apologies if this is blindingly obvious, just a docker enthusiast. I can access my docker container from a remote machine as long as I stay logged in, but if I log out the container stops and is no longer remotely accessible. How do I keep the docker container running when the current user is not actively logged in?

Edit: My apologies for not enough details. Running a dockerized jitsi container. It boots up nicely with "docker start jitsi" and my understanding is "docker start" is already detached (-d) so I can close the shell and the container will continue running and I can connect to it from an external source but if I log out and then try to connect, I can't connect into the jitsi container, I am not precisely sure how to keep the container process running. I've been reading up on it and iterating over some possibilites but no dice so far.

2 Answers

OK...

  1. You can keeping docker service running with the following command sudo systemctl enable docker.service. So, when you restart the server or your development environment, it will keep running.
  2. To docker container keep running after restart or log out session, you must run command docker run -d -p 8080:8080 --restart always plantuml/plantuml-server:jetty for example.

The keywords are --restart always which tell docker to restart the container when the system boots.

If you are using Linux, then you can use nohup on the docker process. This should allow the process to keep running, even when the user who started the process logs out.

nohup (enter the command to run when the user logs out) &

Note: the ampersand is required at the end.

Update: You can open an interactive session with the container, and run the nohup command, instead of running nohup with the Docker command.

Related