If you have heard developers rave about Docker but were not sure where to start, you are in the right place. Learning how to use Docker on Linux opens up a world of portable, efficient application deployment that will change how you think about software. I remember the first time I spun up a container in my homelab – watching an entire application stack come alive with a single command felt like magic.
In this guide, I will walk you through everything from installation to running your first container. No prior experience needed. By the end, you will understand containerization, know the essential commands, and have practical skills you can use immediately.
What is Docker and Why Should You Use It?
Docker is a platform that packages applications into isolated units called containers. Think of a container as a lightweight, self-sufficient box that holds everything an application needs to run: code, libraries, dependencies, and configuration files.
Understanding Containerization
Containerization solves the classic “it works on my machine” problem. When you containerize an app, it runs the same way everywhere – your laptop, a test server, or production. The application does not care what is underneath because it carries its own environment.
The numbers back this up. Gartner estimates over 95% of new digital workloads will run on containerized platforms by 2025. The Docker container market hit $6.12 billion in 2025 and is projected to reach $16.32 billion by 2030. This is not a passing trend – it is the foundation of modern software deployment.
Get a VPS from as low as $11/year! WOW!
Docker vs Virtual Machines
Virtual machines (VMs) include an entire operating system. That means gigabytes of overhead for each VM. Containers share the host kernel, making them:
- Smaller: Megabytes instead of gigabytes
- Faster: Start in seconds, not minutes
- More efficient: Run dozens of containers where you would struggle with a handful of VMs
Docker works alongside the Open Container Initiative, which maintains open standards for container formats. This means your containers are not locked into a single vendor.
Real-World Use Cases
Why should you care? Here is what Docker enables:
- Local development: Spin up databases, web servers, or entire application stacks without polluting your system
- Testing: Create identical environments for consistent results
- Homelab projects: Run Plex, Nextcloud, Pi-hole, and more with easy updates
- Learning: Experiment with new technologies risk-free
Among IT professionals, container usage reached 92% in 2025. Whether you are building a homelab or preparing for a career in DevOps, Docker skills are essential.
Prerequisites Before Installing Docker
Before diving into installation, let us make sure your system is ready. Docker runs on most major Linux distributions including Ubuntu, Debian, Fedora, CentOS, and Arch Linux.
You will need:
- 64-bit Linux: Docker does not support 32-bit systems
- Kernel version 3.10+: Most modern distros exceed this
- At least 4GB RAM: More is better for running multiple containers
- 20GB+ free disk space: Images and containers consume storage quickly
- Sudo or root access: Required for installation
Not sure what you are running? You can check your Linux version with a few simple commands. This helps verify you are on a supported distribution.
How to Install Docker on Linux
Docker version 27.5.1 is the latest stable release as of January 2025. I will cover the two most common distribution families. For other distros, refer to Docker official installation documentation.
Install Docker on Ubuntu/Debian
The recommended approach uses Docker official apt repository. Open your terminal and run these commands:
# Update package index and install prerequisites
sudo apt update
sudo apt install ca-certificates curl gnupg
# Add Docker official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
For Debian, replace ubuntu with debian in the repository URL.
Install Docker on Fedora/RHEL
Fedora and RHEL-based systems use dnf:
# Install dnf-plugins-core
sudo dnf -y install dnf-plugins-core
# Add Docker repository
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
# Install Docker
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker
Verify Docker Installation
Check that Docker installed correctly:
docker --version
# Output: Docker version 27.5.1, build ...
sudo docker run hello-world
The hello-world container pulls a test image and prints a confirmation message. If you see “Hello from Docker!”, you are good to go.
Add User to Docker Group
Notice we used sudo for that last command? By default, Docker requires root privileges. You can fix this by adding your user to the docker group:
sudo usermod -aG docker $USER
Log out and back in for this to take effect. Now you can run Docker commands without sudo. For more details on user management, check our dedicated guide.
Essential Docker Commands Every Linux User Needs
Let me share the commands I use daily. Master these, and you will handle 90% of Docker tasks. For the complete reference, see the Docker command reference.
Image Management Commands
Images are templates for containers. Think of them as blueprints.
docker pull nginx– Download an image from Docker Hubdocker images– List all local imagesdocker rmi nginx– Remove an imagedocker image prune– Remove unused images
Container Management Commands
Containers are running instances of images.
docker run nginx– Create and start a containerdocker ps– List running containersdocker ps -a– List all containers (including stopped)docker stop container_name– Stop a running containerdocker start container_name– Start a stopped containerdocker rm container_name– Remove a containerdocker logs container_name– View container outputdocker exec -it container_name bash– Open a shell inside a container
System Information Commands
Keep your system healthy with these:
docker system df– Show Docker disk usagedocker system prune– Remove unused data (stopped containers, networks, dangling images)docker inspect container_name– Detailed container information
Docker images can consume significant storage over time. It is smart to regularly monitor your disk usage and run cleanup commands.
Creating Your First Docker Container
Time to get hands-on. Let us run a real web server.
Running a Simple Web Server
This command pulls the nginx image and starts a container:
docker run -d -p 8080:80 --name my-webserver nginx
Open your browser and visit http://localhost:8080. You should see the nginx welcome page. That is a fully functional web server running in about two seconds.
Understanding Docker Run Options
Let us break down those flags:
-d– Run in detached mode (background)-p 8080:80– Map port 8080 on your machine to port 80 in the container--name my-webserver– Give your container a memorable name
Without -d, the container runs in the foreground and logs output to your terminal. Useful for debugging, but you will usually want detached mode.
Port Mapping and Volumes
Port mapping connects your host to the container. The format is host_port:container_port.
Volumes persist data beyond the container lifecycle. Without volumes, any data created inside a container disappears when you remove it. Here is an example mounting a local directory:
docker run -d -p 8080:80 -v /home/user/website:/usr/share/nginx/html --name my-site nginx
Now nginx serves files from your /home/user/website folder. Edit those files, refresh your browser, and see changes instantly. I use this setup constantly in my homelab for testing static sites before deploying them.
Docker Best Practices for Linux
After years of running containers, I have learned what separates a stable setup from a maintenance nightmare. Here is what actually matters.
Security Best Practices
Security starts at the foundation. Mark Cavage, President and COO at Docker Inc., put it well:
“Security has to start at the earliest point in development, and needs to be universally available to every developer. By making hardened images freely available and providing tooling that works with today AI coding agents, we are giving the entire industry and community the best possible baseline to build on.”
Key security practices:
- Never run containers as root. Use a non-root user with UID greater than 10,000
- Avoid the
latesttag. Pin specific versions likenginx:1.25.3 - Scan images for vulnerabilities before deploying
- Do not store secrets in images. Use environment variables or secrets management
Image Optimization
Smaller images mean faster deployments and reduced attack surface:
- Use multi-stage builds to separate build tools from runtime
- Start with minimal base images like Alpine when possible
- Create
.dockerignorefiles to exclude unnecessary files from builds - Combine RUN commands to reduce layers
Resource Management
Containers can consume unlimited resources by default. Set limits:
docker run -d --memory="512m" --cpus="1.0" nginx
This caps the container at 512MB RAM and one CPU core. Essential for shared systems or homelabs where you are running multiple services.
Learn about managing Docker as a service with systemctl to control when Docker starts and how to restart it after configuration changes.
Common Docker Mistakes to Avoid on Linux
I have made most of these mistakes myself. Learn from my pain.
- Using
latesttag in production: Todaylatestmight break tomorrow. Always pin versions. - Ignoring permission issues: Docker creates files as root inside containers. This causes headaches when mounting volumes.
- Not persisting data: Containers are ephemeral. Without volumes, database contents vanish when you remove the container.
- Improper apt-get usage: Always run
apt-get update && apt-get installin the same RUN command to avoid cache issues. - Skipping
.dockerignore: Accidentally including node_modules or .git bloats your images. - Exposing secrets: Never hardcode passwords in Dockerfiles. They are visible in image history.
Troubleshooting Docker Issues on Linux
Even experienced users hit snags. Here is how to diagnose common problems.
Container Exits Immediately
The most frustrating issue for beginners. Your container starts and stops instantly. First, check the logs:
docker logs container_name
Common causes:
- The main process crashed (check for error messages)
- The container completed its task (some containers run once and exit)
- Missing environment variables or configuration
For debugging, run interactively: docker run -it image_name bash
Permission Denied Errors
Permission errors plague Linux users more than any other platform. Docker runs as root by default, which causes ownership conflicts with mounted volumes.
Solutions:
- Add your user to the docker group (covered earlier)
- Match container user UID to your host user
- Use
chownto fix file ownership
For deeper understanding, read up on Linux file permissions. This knowledge pays dividends beyond Docker.
Network Connectivity Problems
Containers cannot reach the internet or each other? Start here:
# Check Docker networks
docker network ls
# Inspect a specific network
docker network inspect bridge
On Linux, Docker creates iptables rules that can conflict with your firewall. If you are using UFW, you will want to understand UFW firewall configuration and how Docker interacts with it.
You can also check your network interfaces to verify Docker virtual networks are created properly.
Next Steps: Advanced Docker on Linux
You have got the foundation. Here is where to go next:
- Write Dockerfiles: Create custom images tailored to your applications
- Learn Docker Compose: Define multi-container applications in YAML files
- Explore orchestration: Kubernetes has 92% market share and 5.6 million developers for a reason
- Automate with scripts: Automate tasks with Bash scripts to manage your Docker workflow
- Dive into networking: Bridge, host, overlay – understand when to use each
Docker transforms how you deploy and manage software. What once required careful dependency management and environment configuration now fits in a single command. Start small – containerize one application, get comfortable with the commands, then expand.
The 47% of companies with 1,000+ hosts that have fully embraced Docker did not get there overnight. They started exactly where you are now.
Ready to level up your Linux skills? Explore our other guides on systemctl service management and file permissions to build a solid administration foundation.




