Closing a remote connection while running a docker container

Hi,
I have python code and I use docker installed on a remote machine to run the code using run command in an interactive mode with volume.

The code takes a long time, is there a way to run the code and close the remote connection?

Thanks a lot.
Nada

1 Like

Yes, by SSH into the remote machine where Docker is installed.

If you want to close the connection, you need to use docker run -d (or --detach) to send the process into the background, so you can terminate any connection while the container is still running.

Well, the question was asked in 2020 and it was about running commands in a container interactively. I donā€™t think the problem was SSH-ing into the remote machine, but closing that connection.

One solution is what @bluepuma77 suggested, but that would still require an interactive terminal so the shell keeps the container alive or any command that does the same without -it. Then running docker exec containername sh to start executing the commands interactively, and you are where you started because that process can be terminated as well.

Or you can use a terminal emulator and run the docker run command from the emulated terminal which runs even when the SSH connection is terminated. I recommend tmux.

Of course the best would be not doing anything interactively, but sometimes a container is just used for having a newer version of a software that generates a content to the host through a bind mount, so in that case it is okay.