Docker

Docker Cheatsheet #

Docker is an open-source platform that automates the deployment, scaling, and management of applications using containerization. Containers are lightweight, portable, and consistent across different environments, making Docker a popular choice for developers and system administrators. Docker was first released in 2013 by Docker, Inc.

Docker Installation #

Command/OptionExampleDescription
docker –versiondocker --versionCheck the installed Docker version
docker infodocker infoDisplay system-wide information

Working with Docker Images #

Command/OptionExampleDescription
docker pulldocker pull ubuntuDownload an image from Docker Hub
docker imagesdocker imagesList all images on the local machine
docker rmidocker rmi ubuntuRemove an image from the local machine

Working with Docker Containers #

Command/OptionExampleDescription
docker rundocker run -it ubuntuRun a command in a new container
docker psdocker psList running containers
docker ps -adocker ps -aList all containers, including stopped ones
docker stopdocker stop container_idStop a running container
docker startdocker start container_idStart a stopped container
docker rmdocker rm container_idRemove a container
docker execdocker exec -it container_id bashRun a command in a running container

Managing Docker Volumes #

Command/OptionExampleDescription
docker volume createdocker volume create my_volumeCreate a new volume
docker volume lsdocker volume lsList all volumes
docker volume rmdocker volume rm my_volumeRemove a volume

Working with Docker Networks #

Command/OptionExampleDescription
docker network createdocker network create my_networkCreate a new network
docker network lsdocker network lsList all networks
docker network rmdocker network rm my_networkRemove a network

Docker Compose #

Command/OptionExampleDescription
docker-compose updocker-compose upBuild, (re)create, start, and attach to containers for a service
docker-compose downdocker-compose downStop and remove containers, networks, images, and volumes
docker-compose builddocker-compose buildBuild or rebuild services
docker-compose logsdocker-compose logsView output from containers

Docker Swarm #

Command/OptionExampleDescription
docker swarm initdocker swarm initInitialize a swarm
docker swarm joindocker swarm join --token <token> <manager_ip>Join a node to a swarm
docker service createdocker service create --name my_service nginxCreate a service
docker service lsdocker service lsList services in a swarm
docker node lsdocker node lsList nodes in a swarm

Dockerfile #

Command/OptionExampleDescription
FROMFROM ubuntu:latestSet the base image for subsequent instructions
RUNRUN apt-get update && apt-get install -y python3Execute commands in a new layer on top of the current image
CMDCMD ["python3", "app.py"]Provide defaults for an executing container
COPYCOPY . /appCopy files from the host to the container
EXPOSEEXPOSE 80Inform Docker that the container listens on the specified network ports at runtime

This cheatsheet covers the most commonly used Docker commands and options, helping you to manage Docker images, containers, volumes, networks, and services effectively.

Docker

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.