Docker
Introduction
This cheat sheet provides a quick reference for some common Docker commands and concepts. Docker is a platform for developing, shipping, and running applications in containers.
Installation
To use Docker, you need to install it on your system. Installation methods may vary depending on your operating system. Refer to the official Docker documentation for installation instructions.
Docker Concepts
Images
Pull an image from Docker Hub:
docker pull image_name:tagList all locally available images:
docker imagesRemove an image:
docker rmi image_name:tag
Containers
Create and start a container from an image:
docker run -d --name my_container image_name:tagList all running containers:
docker psList all containers (including stopped ones):
docker ps -aStop a running container:
docker stop container_idRemove a container (must be stopped):
docker rm container_id
Volumes
Create a Docker volume:
docker volume create my_volumeList Docker volumes:
docker volume lsRemove a Docker volume:
docker volume rm my_volume
Networking
List Docker networks:
docker network lsCreate a custom Docker network:
docker network create my_network
Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file to configure application services and environments.
Docker Compose Commands
Start containers defined in a Compose file:
docker-compose up -dStop containers defined in a Compose file:
docker-compose downList running Compose services:
docker-compose psView logs for services:
docker-compose logs
Dockerfile
Dockerfile is a script that contains instructions for building a Docker image.
Building Images with Dockerfile
Build an image from a Dockerfile in the current directory:
docker build -t my_image:tag .Build an image from a Dockerfile in a specific directory:
docker build -t my_image:tag /path/to/dockerfile/dir
Conclusion
This cheat sheet covers some basic Docker commands and concepts. Docker offers a wide range of features and functionality; refer to the Docker documentation for more in-depth information and advanced usage.