How to give shell access to a running Docker container

不言
Release: 2019-03-19 15:21:41
Original
4295 people have browsed it

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 
Copy after login

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
Copy after login

Use container name:

$ sudo docker attach happy_admin
Copy after login

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  bash
Copy after login

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
Copy after login

Use container name:

$ sudo docker exec -it happy_tecadmin bash
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!