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
-tflag – Allocates a pseudo-TTY-iflag – Keeps stdin open even if not attached-dflag – Run container in detached mode--nameoption – Assign a name to the container-poption – Publish a container’s port(s) to the host-voption – Mount a volume--rmoption – 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.
