DEV Community

Cover image for Docker Command Sheet - My Go-To Dev Environment
Devashish Roy
Devashish Roy

Posted on

Docker Command Sheet - My Go-To Dev Environment

A quick reference for commonly used Docker commands.

Designed for everyday development, it shows how to build, run, manage, and push Docker images. Fully generalized with placeholders for paths, image names, container names, and ports. Minimal, non-redundant, and easy to follow for beginners and intermediate users alike.


Basic Docker Commands

# Check installed Docker version
docker version

# Pull an image from Docker Hub
docker pull <image_name>

# Build an image from a Dockerfile (path = directory containing Dockerfile)
docker build -t <image_name> <path_to_dockerfile>

# Run a container interactively
docker run -it <image_name>

# Run a container with port mapping (host → container)
docker run -p <host_port>:<container_port> <image_name>

# Run a container with a custom name
docker run -it --name <container_name> <image_name>

# List running containers
docker container ls

# List all containers (including stopped ones)
docker container ls -a

# Stop a container
docker stop <container_id>

# Remove a container
docker container rm <container_id>

# List all images
docker image ls

# Remove an image
docker image rm <image_id>
Enter fullscreen mode Exit fullscreen mode

Docker Volumes

# Create a named volume
docker volume create <volume_name>

# List all volumes
docker volume ls

# Run a container with a mounted host directory
docker run -it -v <host_path>:<container_path> <image_name>

# Run a container with a named volume
docker run -it -v <volume_name>:<container_path> <image_name> bash
Enter fullscreen mode Exit fullscreen mode

Docker Networking

# List all networks
docker network ls

# Inspect the default bridge network
docker inspect bridge

# Create a new network
docker network create <network_name>

# Run a container inside a specific network
docker run -it --network <network_name> --name <container_name> <image_name>

# Connect an existing container to a network
docker network connect <network_name> <container_name>

# Execute a command inside a running container
docker exec -it <container_name> bash

# Run a container with port mapping
docker run -it -p <host_port>:<container_port> <image_name>
Enter fullscreen mode Exit fullscreen mode

Working with Docker Hub

# Build an image and tag it for Docker Hub
docker build -t <dockerhub_username>/<repo_name> <path_to_dockerfile>

# Push image to Docker Hub
docker push <dockerhub_username>/<repo_name>

# Pull image from Docker Hub
docker pull <dockerhub_username>/<repo_name>

# Run container from Docker Hub image
docker run -it <dockerhub_username>/<repo_name>
Enter fullscreen mode Exit fullscreen mode

This cheatsheet provides a minimal, non-redundant, and fully generalized set of Docker commands for everyday development.

References

Top comments (0)