EN
Docker - connect to container command line
6 points
Hi, today I would like to show you how we can login to docker container command line.
Quick solutions
Using /bin/sh
xxxxxxxxxx
1
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
xxxxxxxxxx
1
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 when our container name is: auth-service-container.
We simply replace 'PUT_CONTAINER_NAME_HERE' with our container name: 'auth-service-container'.
xxxxxxxxxx
1
docker exec -t -i auth-service-container /bin/sh
Output from command line:
xxxxxxxxxx
1
[root@localhost ~]# docker exec -t -i auth-service-container /bin/sh
2
/ # ls -al
3
total 46116
4
drwxr-xr-x 1 root root 42 Oct 8 15:06 .
5
drwxr-xr-x 1 root root 42 Oct 8 15:06 ..
6
-rwxr-xr-x 1 root root 0 Oct 8 15:06 .dockerenv
7
drwxr-xr-x 2 root root 4096 May 9 2019 bin
8
drwxr-xr-x 5 root root 340 Oct 8 15:06 dev
9
drwxr-xr-x 1 root root 66 Oct 8 15:06 etc
10
drwxr-xr-x 2 root root 6 May 9 2019 home
11
drwxr-xr-x 1 root root 132 May 11 2019 lib
12
drwxr-xr-x 3 root root 17 Oct 8 15:06 log
13
drwxr-xr-x 5 root root 44 May 9 2019 media
14
drwxr-xr-x 2 root root 6 May 9 2019 mnt
15
drwxr-xr-x 2 root root 6 May 9 2019 opt
16
dr-xr-xr-x 210 root root 0 Oct 8 15:06 proc
17
drwx------ 1 root root 52 Oct 15 12:17 root
18
drwxr-xr-x 2 root root 6 May 9 2019 run
19
drwxr-xr-x 2 root root 4096 May 9 2019 sbin
20
drwxr-xr-x 2 root root 6 May 9 2019 srv
21
dr-xr-xr-x 13 root root 0 Oct 8 12:24 sys
22
drwxrwxrwt 5 root root 115 Oct 8 15:06 tmp
23
drwxr-xr-x 1 root root 81 May 11 2019 usr
24
drwxr-xr-x 1 root root 19 May 9 2019 var
25
/ # exit
26
[root@localhost ~]#
We can read more about docker exec program here: