docker exec
Sometimes you might want to run commands on containers that are running in detached mode (in the background). docker exec
provides an option to run commands in a running container either in detached mode by using the -d
option or in interactive mode by using the -it
flag. Before running docker exec
, make sure the docker container is running and the container's primary process is running. For executing a command on the running container we would need the container ID or the container name.
Let's say we have created an instance of Redis server container in detached mode using the following command:
docker run -d vishwanathsrikanth/mycacheserver:v1
You can also see the container running using the following command:
docker ps
The preceding command gives the following output:
The following command opens an interactive PowerShell session with the running container:
docker exec -it 5e24c14a2cc6 powershell
Now since we have Redis server running on this container you can connect to the Redis...