Docker ssh into container

In this tutorial, How to use Docker ssh into a 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 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.

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

1 thought on “Docker ssh into container

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.