1

I have a container started as the following:

docker run --interactive --tty --gpus all --name my_container 
--workdir "/home/ubuntu" --user ubuntu 
--volume /hdd/all_cv/paiv/metis:/home/ubuntu/my --publish 8888:8888 my

how do I run interactively with my_container once I reboot my machine?

3
  • docker run a new container in parallel to the existing one, or docker exec a debugging shell, are the usual approaches; have you tried either of these?
    – David Maze
    Jul 27, 2020 at 13:59
  • @DavidMaze I tried docker run, it won't allow me to start a new container with the same name, so what I need to do is actually to use the existing one (and I hope to use it interactively). So the question is how to achieve that with existing docker?
    – william007
    Jul 27, 2020 at 14:01
  • Why does it need to have the same name? Is your issue just that you lose the interactive shell when your system reboots?
    – David Maze
    Jul 27, 2020 at 15:18

2 Answers 2

1

Based on the docker documentation, you can attach back to the detached container using docker attach command:

Use docker attach to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.

So you should try this to have an interactive session with your already running container:

docker attach my_container
1

If your container is stopped, you just need to start it again

docker ps -aq -f name=my_container | xargs docker start $1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.