Home>Article>Operation and Maintenance> How to give shell access to a running Docker container
This article will introduce to you how to let the shell access the running Docker container? Let’s look at the specific content below.
1. Using Docker Attach
You can use the attach command to access the bash shell in the Docker container. But your docker container must be started with /bin/bash.
Use the following syntax to gain shell access to the Docker container.
$ sudo docker attach
For example, your docker container is running with the ID 76DEBAD837D2 and the name happy_admin. Use one of the following commands for the attach method.
Use container ID:
$ sudo docker attach 76debad837d2
Use container name:
$ sudo docker attach happy_admin
2. Use Docker Exec
If the docker container is not used Started by the /bin/bash command. Then you cannot use the attach command. Now, you need to create bash in the container using exec command. Make sure you are using Docker version 1.3 or above.
Use the following syntax to gain shell access to the Docker container.
$ sudo docker exec -itbash
For example, your docker container is running with the ID 76DEBAD837D2 and the name happy_tecadmin. Use one of the following commands with the exec method.
Use container ID:
$ sudo docker exec -it 76debad837d2 bash
Use container name:
$ sudo docker exec -it happy_tecadmin bash
This article is all over here. For more other exciting content, you can pay attention to the PHP Chinese websiteLinux tutorial videocolumn!
The above is the detailed content of How to give shell access to a running Docker container. For more information, please follow other related articles on the PHP Chinese website!