Explore Our DevOps Hub

CheatSheet

Docker Cheatsheet for Beginners: Get Up and Running Fast

Docker revolutionizes application development by creating isolated and portable “containers” for your software. This cheatsheet equips you with essential Docker commands and concepts to launch your containerized journey.

Bash
# Download and install Docker Desktop
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Verify installation
docker run hello-world

Basic Commands:

Bash
# List running containers
docker ps

# List local images
docker images

# Download an image (e.g., MySQL)
docker pull mysql

# Stop a running container (replace "<container_name>")
docker stop <container_name>

# Remove a stopped container (replace "<container_name>")
docker rm <container_name>

# Start a stopped container
docker start <container_name>

# Run a container and execute a command (e.g., Ubuntu)
docker run ubuntu echo "Hello from Ubuntu!"

# Build an image from a Dockerfile in the current directory (replace "<image_name>")
docker build -t <image_name> .

# Create and start a container from an image
docker run -itd  <image_name> /bin/bash {Shell teminal depends on the shell . Ex alpain /bin/sh}

Working with Images:

Bash
# Pull an image (e.g., Nginx)
docker pull nginx

# Build an image from a Dockerfile (replace "<image_name>")
docker build -t <image_name> .

# List images
docker images

# Remove an image (replace "<image_name>")
docker rmi <image_name>

# Prune unused images
docker image prune -af

Container Interaction & Network Command:

Bash
# Run a container (replace "<image_name>" and optional "<container_name>")
docker run -it <image_name> [<container_name>]

# Mount a volume (replace "<host_path>", "<container_path>" and optional "<volume_name>")
docker run -v <host_path>:<container_path> [<volume_name>] <image_name>

# Map a port (replace "<host_port>", "<container_port>")
docker run -p <host_port>:<container_port> <image_name>

# Link containers (replace "<source_container>", "<alias>", and "<target_container>")
docker run --link <source_container>:<alias> <target_container>

# Execute a command in a running container
docker exec -it <container> <command>

# Copy files/folders between host and container
docker cp <container>:<source_path> <dest_path>

# List all networks
docker network ls

# Display detailed information about a network
docker network inspect <network>

Remember:

These snippets are just basic examples. Customize them for your specific needs and refer to the official Docker documentation for more advanced topics.

LEAVE A RESPONSE

Your email address will not be published. Required fields are marked *