Docker Scratchpad
This is a collection of useful Docker commands.
Containers and Images
- Show all running containers:
docker ps - Shows all running and stopped containers:
docker ps -a - Shows only CONTAINER IDs of all running and stopped containers:
docker ps -aq - Stop all running containers:
docker container stop $(docker container ls -aq) - Remove all containers:
docker container rm $(docker container ls -aq) - Show all top level images:
docker images - Remove all images:
docker rmi $(docker images -aq)
Dockerfile
- Build image from Dockerfile in the current directory with tag "sometag":
docker build -t sometag . - Run the container interactively:
docker run -it sometag
Volumes
- List volumes:
docker volume ls - Run the latest nginx image and mount the host directory D:\Volume as a volume \Volume:
docker run -d --name test -v D:/Volume:/Volume nginx:latestRun a bash session interactively in the container named "test" created above:docker exec -it test /bin/bashGet a list of files in the volume:ls VolumeInspect your container to varify the volume:docker inspect test