These are most used docker commands to learn.
Table of Contents
Basic Commands:
docker run
– Run a container from a specific imagedocker start
– Start an existing containerdocker stop
– Stop a running containerdocker rm
– Remove a stopped containerdocker rmi
– Remove an imagedocker ps
– List running containersdocker images
– List all images on the system
Building and Publishing Images:
docker build
– Build an image from a Dockerfiledocker push
– Push an image to a registrydocker pull
– Pull an image from a registry
Networking:
docker network create
– Create a new networkdocker network connect
– Connect a container to a networkdocker network disconnect
– Disconnect a container from a network
Managing Volumes:
docker volume create
– Create a new volumedocker volume rm
– Remove a volumedocker volume ls
– List all volumesdocker volume inspect
– Inspect a volume
Docker Compose:
docker-compose up
– Start all services defined in a Compose filedocker-compose down
– Stop all services defined in a Compose filedocker-compose build
– Build images for all services defined in a Compose filedocker-compose ps
– List all running services defined in a Compose file
Logs and Events
docker logs
– Fetch the logs of a containerdocker events
– Get real-time events from the server
Advanced Commands
docker exec
– Run a command in a running containerdocker attach
– Attach to a running containerdocker cp
– Copy files/folders between a container and the local filesystemdocker diff
– Inspect changes on a container’s filesystem
Tips
-t
flag – Allocates a pseudo-TTY-i
flag – Keeps stdin open even if not attached-d
flag – Run container in detached mode--name
option – Assign a name to the container-p
option – Publish a container’s port(s) to the host-v
option – Mount a volume--rm
option – Automatically remove the container when it exits
Please note that this is a basic cheat sheet, there are many more commands and options available in Docker. This is just a quick reference to get you started.