pantonante
3/5/2018 - 1:03 AM

docker-snippets

Docker useful snippets

Docker

Start a container with a shell and mounted folder

docker run -it -v <shared_folder>:<mounting_path> <image>

Get IP of running container

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name_or_id>

Disable address randomization

If GDB gives the error warning: Error disabling address space randomization: Operation not permitted than run the image with the following flags

docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined

Start an exited container

docker start -a <container_ID>

Sometimes the container doesn't work at all after this command, in that case run:

docker restart <container_ID>
docker attach <container_ID>

Give access to host USB or serial device

docker run -it --device=/dev/ttyUSB0 <image>

Create container from Dockerfile

Assuming there is a valid Dockerfile in the current folder, just run

docker build -t container_name .

Adding volume to existing container

docker commit 5a8f89adeead newimagename
docker run -it -v "$PWD/dir1":/dir1 -v "$PWD/dir2":/dir2 newimagename