Injecting a new process into a running container
While doing development and debugging, we might want to look inside an already running container. There are a few utilities, such as nsenter
(https://github.com/jpetazzo/nsenter), which allow us to enter the namespace of the container to inspect its state. With the exec
option, which was added in Docker 1.3, we can inject a new process inside a running container.
Getting ready
Make sure that the Docker daemon is running on the host and that you can connect through the Docker client. You might also need a running container to inject a process into.
How to do it...
You can inject a process inside a running container with the following command:
$ docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Let's start an nginx
container and then inject bash
into it:
$ ID=$(docker container run -d redis)$ docker container exec -it $ID /bin/bash

How it works...
The exec
command enters the namespace of the container and starts the new process.
See also
Look at the help...