Using Docker on Linux: A Complete Beginner’s Guide (Step-by-Step Tutorial)
🚀 What Is Docker (Explained Like You’re Five)
Imagine you want to run an application, but it needs:
-
a specific version of Python
-
a certain Linux library
-
a particular config file
Instead of installing all that manually, Docker packs everything into a container that works anywhere.
Think of it like a portable mini-computer with everything the app needs.
No conflicts.
No errors.
No dependency headaches.
🛠️ Step 1: Install Docker on Linux
Works for Ubuntu, Debian, Linux Mint
Run these commands:
Add Docker’s GPG key:
Add the Docker repository:
Install Docker:
Check if Docker works:
You should see something like:
Docker version 26.x.x
🧰 Step 2: Allow Running Docker Without sudo
Typing sudo every time is annoying.
Add your user to the docker group:
Then log out and log back in.
Test without sudo:
If no error → you’re good!
🐳 Step 3: Pulling Your First Docker Image
Docker images are like app templates.
Docker containers are running apps from those templates.
Pull an image:
List your images:
Run a container:
Inside the container → try commands:
Exit:
Boom! You just ran Linux inside Linux.
Welcome to the matrix.
📦 Step 4: Running Containers in the Background
Let’s run Nginx (a web server):
-
-d= detached mode (background) -
-p 8080:80= map port 8080 to the container’s port 80
Visit in browser:
You’ll see the Nginx welcome page.
Check running containers:
Stop the container:
🔁 Step 5: Restarting and Removing Containers
See all containers (including stopped ones):
Start a stopped container:
Remove a container:
Remove the image powering it:
🧱 Step 6: Building Your Own Docker Image
Create a file named Dockerfile:
Build it:
Run it:
Congrats!
You created your own container image — like a mini OS you built yourself.
📁 Step 7: Docker Volumes (Saving Data the Right Way)
Containers are temporary.
If they die, your data dies too.
Use volumes to save data:
Now your MySQL data survives container restarts.
Check volumes:
🔗 Step 8: Docker Compose (Super Useful for Beginners)
Docker Compose lets you run multiple containers with one command.
Create docker-compose.yml:
Run it:
Stop:
Easy and powerful.
💡 Practical Real-World Things You Can Do With Docker
-
Run WordPress easily
-
Test PHP, Python, Node.js apps
-
Host a MySQL or PostgreSQL database
-
Deploy apps faster
-
Set up dev environments instantly
-
Learn Linux safely inside containers
-
Run everything isolated and clean
📌 Conclusion
Docker may look scary at first, but once you understand images, containers, volumes, and commands like run, pull, build, and compose, everything becomes easy and fun. This guide gave you the clearest beginner-friendly explanation possible, with step-by-step actions perfect for newbies, students, or developers starting DevOps for the first time.