Day20 of #90DaysOfDevOpsChallenge: The Docker Cheat-sheet🔥
Hello everyone, today I completed Day 20 of my journey.
We learned about Docker, and here is a short list of Docker commands.
Installation and Setup
sudo apt-get update
: Updates the package lists for upgrades and new package installations.sudo apt install
docker.io
: Install Docker.
Container Management
docker ps
: Lists running containers.docker ps -a
: Lists all containers, including stopped ones.docker run [IMAGE_NAME]
: Runs a container using a Docker image (e.g.,docker run mysql:latest
).--name [CONTAINER_NAME]
: Assigns a custom name to the container.-v [HOST_VOLUME]:[CONTAINER_VOLUME]
: Mounts a volume to the container (e.g.,-v mysql-data:/var/lib/mysql
).-e
: Assigns environment variables to the container.
docker stop [CONTAINER_ID]
: Stops a running container.docker start [CONTAINER_ID]
: Starts a stopped container.docker restart [CONTAINER_ID]
: Restarts a container.docker pause [CONTAINER_ID]
: Pauses the container's processes.docker rm [CONTAINER_ID]
: Removes a stopped container.docker kill [CONTAINER_ID]
: Forcefully stops a container.
Image Management
docker pull [IMAGE_NAME]
: Pulls an image from Docker Hub (e.g.,docker pull nginx
).docker push [IMAGE_NAME]
: Pushes an image to a Docker registry.docker images
: Lists all downloaded images.docker rmi [IMAGE_ID]
: Removes an image.docker tag [SOURCE_IMAGE] [NEW_IMAGE]
: Tags an image with a new name.
Volumes
docker volume create [VOLUME_NAME]
: Creates a new volume.docker volume ls
: Lists all Docker volumes.docker volume inspect [VOLUME_NAME]
: Shows detailed information about a specific volume.docker volume rm [VOLUME_NAME]
: Removes a volume.
Networks
docker network ls
: Lists all networks.Bridge: Default network.
Host: Connects containers directly to the host network.
None: Completely isolates the container.
User-defined bridge: Custom network created by the user.
docker network create [NETWORK_NAME]
: Creates a new network.docker network connect [NETWORK_NAME] [CONTAINER_NAME]
: Connects a container to a network.docker network disconnect [NETWORK_NAME] [CONTAINER_NAME]
: Disconnects a container from a network.
Docker Compose Commands
docker-compose --version
: Shows the Docker Compose version.docker-compose up
: Starts services defined in thedocker-compose.yml
file.docker-compose down
: Stops and removes containers, networks, volumes, and images created bydocker-compose up
.docker-compose ps
: Lists containers created by Docker Compose.
Hope you Enjoyed😊
Happy Learning : )
Subscribe to my newsletter
Read articles from Kunal Salve directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by