0

I have a setup where users log into the host machine via PuTTY and can spawn Docker containers for their use.

The Docker command looks like this:

docker run -it --rm -v /home/$USER:/home/$USER -w="/home/$USER" -u $USER --hostname="$USER-gcc463-docked" precise-gcc4 tmux new -s docker-$USER

As you can see, I've used --rm so the container in theory should be removed when the user exits but, in practice, some users close their PuTTY window and the containers are left orphan.

Do you have any ideas how could I make the containers to actually be removed in this case or at least how can I find the orphan ones and clean them up?

Thank you.

1
  • Can you give some ps fauwx output of the example process tree that is still open from a closed SSH session? This isn't really a Docker specific issue. But depending which process is actually being held on to (the actual SSH process still running or just the orphaned shell process) the solution would be slightly different. It isn't something immediately solved by Docker (the same issue would occur with any process still running at disconnect).
    – Andy Shinn
    Sep 17, 2017 at 20:10

2 Answers 2

0

docker ps -a will help you find containers that haven't been cleaned up.

1
  • Nope, in my case they don't have the status "Exited"
    – emmerich
    Sep 15, 2017 at 16:56
0

My solution was wrap the docker run into a script with a trap, something like

trap "if docker ps | grep -c ${CONTAINER_NAME}; then docker stop ${CONTAINER_NAME}; fi" 0 1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .