Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to give shell access to a running Docker container

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the method of allowing shell to access the running Docker container, which is very detailed and has certain reference value. Friends who are interested must read it!

1. Use Docker Attach

You can use the attach command to access bash shell in the Docker container. But your docker container must be started with / bin/bash.

Use the following syntax to get shell access to the Docker container.

$sudo docker attach

For example, your docker container is running and its ID is 76DEBAD837D2 and its name is happy_admin. Use one of the following commands for the attach method.

Use the container ID:

$sudo docker attach 76debad837d2

Use the container name:

$sudo docker attach happy_admin

2. Use Docker Exec

If the docker container is not started with the / bin/bash command. Then you cannot use the attach command. Now you need to use the exec command to create a bash in the container. Make sure you are using a version of Docker above 1.3.

Use the following syntax to get shell access to the Docker container.

$sudo docker exec-it bash

For example, your docker container is running and its ID is 76DEBAD837D2 and its name is happy_tecadmin. Use one of the following commands with the exec method.

Use the container ID:

$sudo docker exec-it 76debad837d2 bash

Use the container name:

The above $sudo docker exec-it happy_tecadmin bash is all about the methods that let shell access the running Docker container. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report