Languages
[Edit]
EN

Docker - connect to container command line

6 points
Created by:
Richard-Bevan
413

Hi, today I would like to show you how we can login to docker container command line.

Quick solutions

Using /bin/sh

docker exec -t -i PUT_CONTAINER_NAME_HERE /bin/sh

Using /bin/bash

Second option when our linux doesn't have /bin/sh, we need to use another shell /bin/bash

docker exec -t -i PUT_CONTAINER_NAME_HERE /bin/bash

If we don't have /bin/bash then this command will output the error

(OCI runtime exec failed, more here: to problem description and solution)

Practical example

Practical example when our container name is: auth-service-container.

We simply replace 'PUT_CONTAINER_NAME_HERE' with our container name: 'auth-service-container'.

docker exec -t -i auth-service-container /bin/sh

Output from command line:

[root@localhost ~]# docker exec -t -i auth-service-container /bin/sh
/ # ls -al
total 46116
drwxr-xr-x    1 root     root            42 Oct  8 15:06 .
drwxr-xr-x    1 root     root            42 Oct  8 15:06 ..
-rwxr-xr-x    1 root     root             0 Oct  8 15:06 .dockerenv
drwxr-xr-x    2 root     root          4096 May  9  2019 bin
drwxr-xr-x    5 root     root           340 Oct  8 15:06 dev
drwxr-xr-x    1 root     root            66 Oct  8 15:06 etc
drwxr-xr-x    2 root     root             6 May  9  2019 home
drwxr-xr-x    1 root     root           132 May 11  2019 lib
drwxr-xr-x    3 root     root            17 Oct  8 15:06 log
drwxr-xr-x    5 root     root            44 May  9  2019 media
drwxr-xr-x    2 root     root             6 May  9  2019 mnt
drwxr-xr-x    2 root     root             6 May  9  2019 opt
dr-xr-xr-x  210 root     root             0 Oct  8 15:06 proc
drwx------    1 root     root            52 Oct 15 12:17 root
drwxr-xr-x    2 root     root             6 May  9  2019 run
drwxr-xr-x    2 root     root          4096 May  9  2019 sbin
drwxr-xr-x    2 root     root             6 May  9  2019 srv
dr-xr-xr-x   13 root     root             0 Oct  8 12:24 sys
drwxrwxrwt    5 root     root           115 Oct  8 15:06 tmp
drwxr-xr-x    1 root     root            81 May 11  2019 usr
drwxr-xr-x    1 root     root            19 May  9  2019 var
/ # exit
[root@localhost ~]#

We can read more about docker exec program here:

Alternative titles

  1. Docker - login to container command line
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Docker - useful wiki posts

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join