Docker Commands 101
6 min read
•
0 views
I spent last weekend diving deep into Docker and came out the other side with a solid understanding of its fundamentals. To cement what I learned, I created this command cheat sheet. It's aimed at helping you (and future me!) work confidently with Docker day-to-day.
🐳 Checking Docker Version
Shows the version of Docker installed on your machine.
🔍 Inspecting Containers
List running containers:
List all containers (running + stopped):
aor-all: Show all containers, not just running ones.
🗑️ Removing Containers and Images
Remove a container:
List all images:
Remove an image:
rmi: Remove one or more images by name or ID.
🏗️ Creating and Running Containers
Run a container interactively:
i: Keep STDIN open.
t: Allocate a pseudo-TTY (interactive shell).
Run in background (detached mode):
d: Detached mode. Runs in background.
Run with a specific name:
-name: Assign a custom name to the container.
📥 Pulling Docker Images
Downloads an image from Docker Hub.
▶️ Start and Stop Containers
Start an existing container:
Stop or kill a container:
stop: Graceful shutdown.
kill: Immediate termination.
🛠️ Running Commands in Containers
Execute a one-off command:
Start an interactive shell:
Exit container but keep it running:
🧱 Building Images
t: Tags the image with a name.
<path>: Typically.to refer to the current directory.
Example:
🌐 Port Mapping
p: Maps ports from container to host.
- Example:
Update port mapping for an existing container:
🌱 Environment Variables
You can pass multiple
-e flags for multiple environment variables.Example:
📦 Docker Volumes
Create a volume:
List all volumes:
Mount a volume to a container:
v: Mounts a volume.
/data/db: Where MongoDB stores its data internally.
🔗 Docker Networks
Create a custom network:
List networks:
Types of Docker networks:
bridge: Default. Isolated internal network on the host.
host: Shares host's networking directly.
Run a container on a specific network:
🚀 Push Custom Images to Docker Hub
Step-by-step:
- Create a repo on hub.docker.com (e.g.,
myusername/myimage)
- Tag the image locally:
- Log in:
- Push:
🧩 Docker Compose
Example docker-compose.yaml
Run the compose setup:
Tear down everything:
This sheet is still evolving as I go deeper into Docker, but I hope it helps you as much as it helps me stay productive and confident.
