Skip to main content

Docker Cheatsheet

Images#

# build the image
docker build -t my-image:latest .
# tag the image
docker tag my-image:latest repo/my-image:v1.0.0
# login to a private registry
docker login
# push the image
docker push repo/my-image:v1.0.0
# pull an image
docker pull repo/my-image:latest

Containers#

# Starting a nginx container
docker container run --name proxy -p 8080:80 -d nginx
# Staring a MySQL container
docker container run --name db -e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-p 3306:3306 -d mysql
# Listing running containers
docker container ls
# Listing all containers
docker container ls -a
# Stop a running container
docker stop <container-name>
# Restart a stopped container
docker start <container-name>
# Remove one or more containers
docker container rm <container1-name> <container2-name>
# Follow the logs of container
docker container logs -f <container-name>
# Monitor containers
docker container top <container-name>
docker container inspect <container-name>
docker container stats
# Start a new container and execute a command
docker container run -it —name proxy busybox sh
# Executing a command inside a running container
docker container exec -it <container-name> bash