Home >Operation and Maintenance >Linux Operation and Maintenance >How to give shell access to a running Docker container

How to give shell access to a running Docker container

不言
不言Original
2019-03-19 15:21:414538browse

This article will introduce to you how to let the shell access the running Docker container? Let’s look at the specific content below.

How to give shell access to a running Docker container

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 <CONTAINER ID/NAME>

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 -it <CONTAINER ID/NAME> bash

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 website Linux tutorial video column!

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn