In this tutorial, How to use Docker ssh into container already running. The descriptions command as below:
- Using docker ps command to get the name of the existing container.
- To use docker exec -it <container name> /bin/bash command to get a bash shell in the container.
- To use docker exec -it <container name> <command> to execute whatever command you specify in the container.
“Build, Manage and Secure Your Apps Anywhere. Your Way.” Quote from docker!
Docker ssh into container
To use docker ps command to get the name CONTAINER ID, IMAGE, COMMAND, CREATED, NAMES.
[huupv@docker ~]$ sudo docker ps
Docker exec command to get bash shell in the container with option -it, The docker exec command to get bash shell 59e59adcc0b4 container ID as below:
[huupv@docker ~]$ sudo docker exec -it 59e59adcc0b4 /bin/bash
To use docker exec command to execute whatever command you specify in the container. To display the content /etc/hosts file for container ID 59e59adcc0b4
[huupv@docker ~]$ sudo docker exec -it 59e59adcc0b4 cat /etc/hosts
Conclusion
Thought the article, you log in the containers via docker exec command. sometimes, you execute some command from docker host. The display hosts in the container’s ID or to check networking ping from the containers. How to use Docker ssh into a container already running. Thank you for reading the DevopsRoles page!
Helpful me! Thanks