Docker Run command on an already existing docker container


Example

docker exec -it <container id> /bin/bash

It is common to log in an already running container to make some quick tests or see what the application is doing. Often it denotes bad container use practices due to logs and changed files should be placed in volumes. This example allows us log in the container. This supposes that /bin/bash is available in the container, it can be /bin/sh or something else.

docker exec <container id> tar -czvf /tmp/backup.tgz /data
docker cp <container id>:/tmp/backup.tgz .

This example archives the content of data directory in a tar. Then with docker cp you can retrieve it.