How to SSH into a running Docker Container in different ways
Published on Aug. 22, 2023, 12:14 p.m.
Docker is used to creating containers. In this tutorial, we examine how to SSH into a running Docker Container in different ways like using the docker exec , docker attach command.
Using “docker exec”
Different commands can be run by using the “docker exec” as well as the bash can be also started. A container can be started by using the “docker run” command .
$ sudo docker run --name myubuntu -d ubuntu
Then we should list the running container name.
$ sudo docker ps
The syntax of the “docker exec” command to run bash shell is .
$ sudo docker exec -it ubuntu /bin/bash
Using “docker attach”
Another way to SSH into the running docker container is using the “docker attach .
$ sudo docker attach myubuntu