Docker Cheatsheet

Docker commands for building, running, and managing containerized applications

DevOps6 commandsintermediate

Overview

Docker is a containerization platform that packages applications with their dependencies.

Why It Matters

Docker containerization simplifies deployment and ensures consistency across environments.

Essential Commands

docker build -t app:latest .

Build image from Dockerfile

docker run -p 3000:3000 app:latest

Run container and publish port

docker ps -a

List running and stopped containers

docker logs -f <container>

Follow container logs

docker exec -it <container> sh

Open shell inside running container

docker compose up -d

Start multi-service stack in background

Quick Start

Master build images with dockerfiles first

Key Concepts

Build images with Dockerfiles

Manage containers and volumes

Use Docker Compose for multi-container applications

Pro Tips

  • Combine multiple commands for powerful workflows
  • Use aliases to speed up your command entry
  • Create scripts to automate repetitive tasks

Common Pitfalls to Avoid

  • Forgetting to check the documentation for edge cases
  • Running commands without understanding their full impact
  • Not testing changes in a safe environment first

Related Resources

10 items