Docker Commands
Here’s a list of commands to remember for docker administration.
List Containers
To list all docker containers on a host:
sudo docker ps -a
Remove Containers
To remove all docker containers on a host:
sudo docker rm -f $(sudo docker ps -aq)
Container Logs
To see the logs for a container:
sudo docker logs containername
Container Stats
To get the stats of docker containers, as a single snapshot:
docker stats --no-stream
Additional commands are here: How To Remove Docker Images, Containers, and Volumes | DigitalOcean
Copy Files from Container
To copy files out of a docker container, do this:
sudo docker cp <imageid>:/pathincontainer ~/pathonhost
Running a Terminal Container
Sometimes, it’s necessary to spin up a blank docker container for testing network or other facilities from a terminal session in the container.
Here’s a quick command that will spin up a container with an ubuntu bash terminal.
NOTE: It also adds an /etc/hosts entry of (host.docker.internal) which is the docker entry for accessing the container’s host machine.
This is useful if you are testing visibility of any host services from the container.
docker run --rm -it --add-host host.docker.internal:host-gateway --entrypoint bash ubuntu
Once started and at the terminal, you can install network utilities such as ping, curl, etc with this:
apt-get update; apt-get install curl; apt-get install inetutils-ping; apt-get install net-tools
Get Docker Gateway Address
Here’s a pair of commands to get the docker’s bridge network gateway address and subnet:
docker network inspect bridge --format='{{(index .IPAM.Config 0).Gateway}}'
docker network inspect bridge --format='{{(index .IPAM.Config 0).Subnet}}'
No Comments