1

I have accessed a Remote Machine (call it , RM) through SSH (from my host). And I am running a docker image inside RM via my SSH session. Both are Ubuntu 16.04 based.

There are some processes running inside this docker container, so I can't exit the container.

So,how do I detach this ssh session from my host, so that those processes inside the docker would still run unaffected.

I am doing this, because I have to restart my host machine for some purpose.

PS: In this link Correct way to detach from a container without stopping it, it's not running the docker container via SSH session. So two scenarios are different.

rpratesh
  • 51
  • 1
  • 8
  • 1
    If you run your container in detached mode (with the -d flag), then exiting your SSH session will not affect it. – Oliver Charlesworth Dec 27 '18 at 11:51
  • Yeh.. but I have already started the container without -d flag and was running bash inside it. So, any way to disown it now – rpratesh Dec 27 '18 at 11:53
  • 1
    Possible duplicate of [Correct way to detach from a container without stopping it](https://stackoverflow.com/questions/25267372/correct-way-to-detach-from-a-container-without-stopping-it) – Peter Halligan Dec 27 '18 at 11:58

1 Answers1

0

First, you have to start your Docker container in daemon (non-interactive) mode, using -d argument and dropping -it. Don't forget to name your container for further usage with --name foo option.

After container is started, you can control it using docker exec -it foo sh-or-whatever. If your ssh session will terminate, container will continue running. However, you docker exec session will be over.

grapes
  • 8,185
  • 1
  • 19
  • 31