SSH to a running docker container
Docker containers are created based on images. If you want to create a new container based on a fedora image and run a terminal on it you can do:
1
docker run -i -t fedora bash
Every time you execute this command a new container will be created based on the fedora image.
Most of the time we run docker containers with servers in a daemonized mode. Here is a very simple example:
1
docker run -i -d fedora bash
In this scenario, we know the container is running, but we can’t really interact with it anymore. If something is not working correctly and we want to debug why, we need to create a new container with a shell and try to reproduce all the steps that led to the error. Well, at least that was the way I used to do it.