Last Updated: November 08, 2019
·
377
· dfang

docker tips

Enter into ANY Container

# get a shell into 'redis' container namespace
$ docker run --rm -it --privileged --pid=container:redis walkerlee/nsenter -t 1 -m -u -i -n sh

you can replace redis to another docker container name or docker container id

Enter into Docker Host

You can use --pid=host to enter into Docker host namespaces.

# get a shell into Docker host
$ docker run --rm -it --privileged --pid=host walkerlee/nsenter -t 1 -m -u -i -n sh

Use the Docker Host Network Stack

$ docker run --net=host ...

The new container will attach to the same network interfaces as the Docker host.

Use Another Container’s Network Stack

$ docker run --net=container:<name|id> ...
The new container will attach to the same network interfaces as the other container. The target container can be specified by id or name.

Clean

docker system prune
docker image prune

for old versions, docker-clean

or this gist