Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to give shell access to a running Docker container

Shulou Source: shulou.com Published: 2022-06-02 04:35:33 10月04日 Update

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!

Tags: Container command method in progress run name content grammar value interest buddy more permissions version knowledge article industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple macOS Shulou Tech Info Docker