Skip to content

Docker

Build Image

docker build -t <new image name> <dockerfile path>  # Create image using this directory's Dockerfile

Run Image

docker run -d <image name>                  # Run an image
docker run -p 4000:80 <image name>          # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 <image name>       # Same thing, but in detached mode

Docker Container

docker container ls                                 # List all running containers
docker container ls -a                              # List all containers, even those not running
docker container stop <hash>                        # Gracefully stop the specified container
docker container kill <hash>                        # Force shutdown of the specified container
docker container rm <hash>                          # Remove specified container from this machine
docker container rm $(docker container ls -a -q)    # Remove all containers
docker rm $(docker ps -a -q)                        # Remove all containers

Shell into a Container

docker exec -ti <container name> /bin/bash

Docker Image

docker image ls -a                          # List all images on this machine
docker image rm <image id>                  # Remove specified image from this machine
docker image rm $(docker image ls -a -q)    # Remove all images from this machine
docker rmi $(docker images -q)              # Remove all images from this machine

Docker Hub

docker login                        # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag      # Tag <image> for upload to registry
docker push username/repository:tag             # Upload tagged image to registry
docker run username/repository:tag              # Run image from a registry