A user can enter a running container in a new interactive bash shell with exec
command.
Say a container is called jovial_morse
then you can get an interactive, pseudo-TTY bash shell by running:
docker exec -it jovial_morse bash
If you want to enter a container as a specific user, you can set it with -u
or --user
parameter. The username must exists in the container.
-u, --user
Username or UID (format:<name|uid>[:<group|gid>]
)
This command will log into jovial_morse
with the dockeruser
user
docker exec -it -u dockeruser jovial_morse bash
If you want to log in as root, just simply use the -u root
parameter. Root user always exists.
docker exec -it -u root jovial_morse bash
You can also log into a image with the run
command, but this requires an image name instead of a container name.
docker run -it dockerimage bash
You can log into an intermediate image as well, which is created during a Dockerfile build.
Output of docker build .
$ docker build .
Uploading context 10240 bytes
Step 1 : FROM busybox
Pulling repository busybox
---> e9aa60c60128MB/2.284 MB (100%) endpoint: https://cdn-registry-1.docker.io/v1/
Step 2 : RUN ls -lh /
---> Running in 9c9e81692ae9
total 24
drwxr-xr-x 2 root root 4.0K Mar 12 2013 bin
drwxr-xr-x 5 root root 4.0K Oct 19 00:19 dev
drwxr-xr-x 2 root root 4.0K Oct 19 00:19 etc
drwxr-xr-x 2 root root 4.0K Nov 15 23:34 lib
lrwxrwxrwx 1 root root 3 Mar 12 2013 lib64 -> lib
dr-xr-xr-x 116 root root 0 Nov 15 23:34 proc
lrwxrwxrwx 1 root root 3 Mar 12 2013 sbin -> bin
dr-xr-xr-x 13 root root 0 Nov 15 23:34 sys
drwxr-xr-x 2 root root 4.0K Mar 12 2013 tmp
drwxr-xr-x 2 root root 4.0K Nov 15 23:34 usr
---> b35f4035db3f
Step 3 : CMD echo Hello world
---> Running in 02071fceb21b
---> f52f38b7823e
Notice the ---> Running in 02071fceb21b
output, you can log into these images:
docker run -it 02071fceb21b bash