Docker Cheatsheet: Everything You Need to Get Started
Whether you’re a beginner or just need a quick reference, this Docker cheatsheet will help you install Docker, run containers, create your own images, and use Docker Compose with confidence.
Installing Docker on Ubuntu
Start by removing any old versions:
sudo apt-get remove docker docker-engine docker.io containerd runc
The easiest way to install Docker is via their official convenience script:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Check Docker version:
docker --version
📖 Full installation guide: Official Docs
Basic Docker Commands
Task | Command |
---|---|
Run a container | docker run nginx |
List running containers | docker ps |
List all containers | docker ps -a |
Stop a container | docker stop <container_name> |
Remove a container | docker rm <container_name> |
List all images | docker images |
Remove an image | docker rmi <image_name> |
Pull an image | docker pull nginx |
Run a command inside a container | docker exec <container_id> <command> |
View container details | docker inspect <container_id> |
📝 Note: A container stops when the process inside it stops.
🖥️ Access Docker Container Shell
docker exec -it <container_name_or_id> bash
Port Mapping
Expose a container’s internal port to the outside world:
docker run -p 80:5000 kodeloud/simple-webapp
Here, 80
is your host port, and 5000
is the container port.
Folder Mapping (Volumes)
Map a host directory to a container directory to persist data:
docker run -v /host/dir:/container/dir mysql
View Container Logs
docker logs <container_id>
Run Containers in Background (Detached Mode)
docker run -d ubuntu sleep 100
To attach later:
docker attach <container_id>
Creating Your Own Docker Image
-
Write a
Dockerfile
-
Build the image:
docker build -t your_username/app_name .
- Push to Docker Hub:
docker push your_username/app_name
Dockerfile Basics
FROM ubuntu
RUN apt-get update && apt-get install -y python3 pip
RUN pip install flask flask-mysql
COPY . /opt/source-code
ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run
📌 Key Points:
-
FROM
defines the base image. -
RUN
executes commands. -
COPY
brings files into the image. -
ENTRYPOINT
defines the default command when the container starts.
Try Docker Manually
docker run -it ubuntu bash
apt-get update
apt-get install -y python3 pip
Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Dockerfile vs Docker Compose
-
Dockerfile: Describes how to build a single image.
-
docker-compose.yml: Describes how to run multi-container applications.
💡 Workflow:
-
Build images with Dockerfile.
-
Define containers with
docker-compose.yml
. -
Run the stack using Docker Compose.
Docker Compose Commands
Task | Command |
---|---|
Launch in background | docker-compose up -d |
Set custom image name | docker-compose --project-name myapp up |
Validate config | docker-compose config |
Clean Up Docker
# Stop all running containers
docker stop $(docker ps -aq)
# Remove all containers
docker rm $(docker ps -aq)
# Remove all images
docker rmi $(docker images -q)
🔗 Useful References
Final Tips
- Always name your containers and volumes for easier management.
- Use
.dockerignore
like.gitignore
to avoid copying unnecessary files. - Combine multiple
RUN
instructions into one to reduce image layers.
👋 About Me
Hi, I’m Shuvangkar Das, a power systems researcher with a Ph.D. in Electrical Engineering from Clarkson University. I work at the intersection of power electronics, DER, IBR, and AI — building greener, smarter, and more stable grids. Currently, I’m a Research Engineer at EPRI (though everything I share here reflects my personal experience, not my employer’s views).
Over the years, I’ve worked on real-world projects involving large scale EMT simulation and firmware development for grid-forming and grid following inverter and reinforcement learning (RL). I also publish technical content and share hands-on insights with the goal of making complex ideas accessible to engineers and researchers.
📺 Subscribe to my YouTube channel, where I share tutorials, code walk-throughs, and research productivity tips.
Leave a comment