0% found this document useful (0 votes)
69 views6 pages

Docker Cheat Sheet

The document provides a cheat sheet on Docker commands for building, cleaning up, interacting with, inspecting, managing images and containers, running services, and networking. It lists and describes common Docker commands in these categories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views6 pages

Docker Cheat Sheet

The document provides a cheat sheet on Docker commands for building, cleaning up, interacting with, inspecting, managing images and containers, running services, and networking. It lists and describes common Docker commands in these categories.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Three. Two.

Online

Docker
Cheat Sheet
Docker Cheat Sheet 1

Launch your own website with unlimited hosting.


Use HostingerTutorials discount code and
get up to 83% OFF any web hosting plan.

Use Code

Docker Cheat Sheet


Build Commands

docker build docker build https://yourserver/file.tar.


gz
Builds an image from a Dockerfile located in the
current directory Builds an image from a remote tar archive

docker build https://github.com/ docker build -t image:1.0 -<<EOF


docker/rootfs.git#container:docker FROM busybox
RUN echo “hello world”
Builds an image from a remote GIT repository
EOF

Builds an image via a Dockerfile that is passed


docker build -t imagename/tag through STDIN
Builds, and tags an image for easier tracking

Clean Up Commands

docker image prune docker image rm image


Clears an unused image Removes an image

docker image prune -a docker rm container

Clears all images that are not being used by Removes a running container
containers

docker kill $ (docker ps -q)


docker system prune
Stops all running containers
Removes all stopped containers, all networks
not used by containers, all dangling images, and
all build cache

HOSTINGER Three. Two. Online


Docker Cheat Sheet 2

docker kill $ (docker ps -q) docker rm $(docker ps -a -q)


Stops all running containers Removes all stopped containers

docker stack rm stackname docker kill $ (docker ps -q)

Removes a swarm Stops all running containers

docker volume rm $(docker volume ls


-f dangling=true -q)

Removes all dangling volumes

Container Interaction Commands

docker start container docker attach container


Starts a new container Attaches to a running container

docker stop container docker wait container

Stops a container Waits until the container is terminated and


shows the exit code

docker pause container


docker commit -m “commit message”
Pauses a container -a “author” container username/
image_name: tag
docker unpause container Saves a running container as an image

Unpauses a container
docker logs -ft container
docker restart container Follows container logs

Restarts a container
docker exec -ti container script.sh
docker wait container Runs a command in a container

Blocks a container
docker commit container image
docker export container Creates a new image from a container

Exports container contents to a tar archive


docker create image

Creates a new container from an image

HOSTINGER Three. Two. Online


Docker Cheat Sheet 3

Container Inspection Commands

docker ps docker inspect container

Lists all running containers Displays low-level information about a


container

docker -ps -a
docker logs container
Lists all containers
Gathers the logs for a container

docker diff container


docker stats container
Inspects changes to directories and files in the
container filesystem Shows container resource usage statistics

docker top container

Shows all running processes in an existing


container

Manage Images Commands

docker image ls docker history image

Lists images Displays the image history

docker image rm mysql docker inspect image

Removes an image Displays low-level information about an image

docker tag image tag

Tags an image

HOSTINGER Three. Two. Online


Docker Cheat Sheet 4

Run Commands

Docker uses the run command to create containers from provided images. The default syntax for this
command:

docker run [options] image [command] [arg...]

Then you can use one of the following flags:

--detach , -d --network

Runs a container in the background and Connects a container to a network


prints the container ID

--rm
--env , -e
Removes container when it stops
Sets environment variables

--read-only
--hostname , -h
Sets the container filesystem as read-only
Sets a hostname to a container

--workdir , -w
--label , -l
Sets a working directory in a container
Creates a meta data label for a container

--name

Assigns a name to a container

Registry Commands

docker login docker push repo/ rhel-httpd:latest

Log ins to a registry Pushes an image to a registry

docker logout docker search term

Logs out from a registry Searches Docker Hub for images with the
specified term

docker pull mysql

Pulls an image from a registry

HOSTINGER Three. Two. Online


Docker Cheat Sheet 5

Service Commands

docker service ls docker service create image

Lists all services running in a swarm Creates a new service

docker stack services stackname docker service scale servicename=10

Lists all running services Scales one or more replicated services

docker service ps servicename docker service logs stackname


servicename
Lists the tasks of a service
Lists all service logs

docker service update servicename

Updates a service

Network Commands

docker network create networkname docker network connect networkname


container
Creates a new network
Connects a container to a network

docker network rm networkname


docker network disconnect
Removes a specified network networkname container
Disconnects a container from a network
docker network ls

Lists all networks docker network inspect networkname


Displays a detailed information about a network

HOSTINGER Three. Two. Online

You might also like