Docker has become one of the most important tools in modern software development, DevOps, cloud engineering, and system administration.
Whether you are building microservices, running databases, deploying web applications, experimenting with Kubernetes, or setting up an AI development environment, Docker provides a consistent way to package and run applications.
In this guide, we'll install Docker Engine on Ubuntu using Docker's official APT repository.
The process is straightforward and works well for developers, DevOps engineers, SREs, system administrators, and anyone learning containerization.
๐ณ What Is Docker?
Docker is a containerization platform that allows applications and their dependencies to run inside isolated environments called containers.
Instead of installing every application dependency directly onto your Ubuntu system, you can package an application into a container and run it consistently across different environments.
A typical Docker workflow looks like this:
Application
↓
Dockerfile
↓
Docker Image
↓
Docker Container
↓
Application RunningFor example, instead of installing a database directly on Ubuntu, you could run PostgreSQL inside a Docker container.
๐งฉ Prerequisites
Before installing Docker, make sure you have:
- An Ubuntu system
- Internet connectivity
- A user with
sudoprivileges - A terminal
- Basic familiarity with Linux commands
It is also a good idea to update your system before starting.
๐ Step 1: Update Ubuntu
Open Terminal:
Ctrl + Alt + TThen run:
sudo apt update && sudo apt upgrade -yThis updates the package index and installs available package upgrades.
Depending on how recently your system was updated, this may take a few minutes.
๐ฆ Step 2: Install Required Dependencies
Docker's repository setup requires several supporting packages.
Install them with:
sudo apt install -y ca-certificates curl gnupg lsb-releaseThese packages provide tools required to securely access and configure external APT repositories.
๐ Step 3: Add Docker's Official GPG Key
Create the directory used to store APT repository keys:
sudo mkdir -p /etc/apt/keyringsNow download Docker's official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgThe key allows APT to verify packages obtained from Docker's repository.
๐️ Step 4: Add the Docker APT Repository
Next, configure Ubuntu to use Docker's official package repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullThis command dynamically detects:
- Your CPU architecture
- Your Ubuntu release codename
- Docker's stable repository
The repository configuration is written to:
/etc/apt/sources.list.d/docker.list๐ Step 5: Update the Package Index
Now refresh Ubuntu's package index again:
sudo apt updateAt this point, Ubuntu should be able to retrieve package information from Docker's repository.
You can optionally verify that Docker packages are available:
apt-cache policy docker-ceIf the repository is configured correctly, you should see Docker package information.
๐ณ Step 6: Install Docker Engine
Now install Docker Engine and the associated components:
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginThis installs several important Docker components.
Docker Engine
docker-ceThe Docker Engine package provides the core container runtime and daemon.
Docker CLI
docker-ce-cliThis provides the docker command-line interface.
containerd
containerd.ioContainerd provides the underlying container runtime infrastructure used by Docker.
Buildx
docker-buildx-pluginBuildx provides modern Docker image-building functionality.
Docker Compose
docker-compose-pluginThis provides the modern:
docker composecommand.
Notice that modern Docker Compose uses a space:
docker composerather than the older:
docker-compose๐ Step 7: Verify Docker Installation
Check the Docker service:
sudo systemctl status dockerYou should normally see that the service is:
active (running)You can also check the Docker version:
docker --versionAnd verify Docker Compose:
docker compose versionFor example:
Docker version ...
Docker Compose version ...The exact version will depend on the current Docker repository packages.
๐งช Step 8: Run Your First Docker Container
The easiest way to verify the installation is to run Docker's test image:
docker run hello-worldDocker will:
- Check whether the
hello-worldimage exists locally. - Download it if necessary.
- Create a container.
- Start the container.
- Display the test message.
- Exit the container.
If everything is working correctly, you should see:
Hello from Docker!๐ Your Docker installation is working!
๐ค Step 9: Run Docker Without sudo
By default, Docker commands may require administrative privileges depending on how your system is configured.
For example:
sudo docker psIf you want your current user to execute Docker commands without sudo, add the user to the Docker group:
sudo usermod -aG docker $USERThen apply the new group membership to your current shell:
newgrp dockerNow try:
docker psIf the configuration is correct, you should no longer need:
sudo⚠️ Important Docker Permission Warning
Adding your user to the docker group is convenient, but it has a significant security implication.
Membership in the Docker group effectively provides root-level control over the host system because Docker can be used to create containers with powerful access to the host.
Therefore:
Only add trusted users to the Docker group.
For a personal development machine, this is commonly acceptable. On a shared or security-sensitive server, evaluate the implications carefully.
๐ Check Whether Docker Starts Automatically
Docker is normally configured as a system service.
You can check its status with:
systemctl status dockerYou can also check whether it is enabled at boot:
systemctl is-enabled dockerIf necessary, enable it:
sudo systemctl enable --now dockerThis both enables Docker at boot and starts it immediately.
๐งฐ Useful Docker Commands
Once Docker is installed, these commands are worth learning.
List running containers
docker psList all containers
docker ps -aList downloaded images
docker imagesDownload an image
docker pull ubuntuRun an Ubuntu container
docker run -it ubuntu bashStop a container
docker stop <container_name_or_id>Remove a container
docker rm <container_name_or_id>Remove an image
docker rmi <image_name_or_id>View Docker information
docker infoView Docker disk usage
docker system df๐งฉ Docker Compose
Docker Compose becomes especially useful when your application consists of multiple services.
For example:
Web Application
│
├── PostgreSQL
│
├── Redis
│
└── APIInstead of manually starting every container, you can define the entire application stack in a compose.yaml file.
For example:
services:
web:
image: nginx
ports:
- "8080:80"Start it with:
docker compose up -dCheck the services:
docker compose psStop them with:
docker compose down๐ ️ Common Problems
Docker command not found
If you receive:
docker: command not foundverify that Docker was installed:
apt-cache policy docker-ceThen check:
which dockerDocker Service Isn't Running
Check:
sudo systemctl status dockerTry starting it:
sudo systemctl start dockerThen test:
docker run hello-worldPermission Denied
If:
docker psreturns a permission error, try:
sudo usermod -aG docker $USER
newgrp dockerThen:
docker psIf the new group membership has not propagated as expected, log out and log back in.
๐ Docker Security Best Practices
Installing Docker is only the beginning. If you plan to use Docker on a production or Internet-facing server, security deserves additional attention.
Consider:
- Using trusted container images
- Keeping Docker updated
- Avoiding unnecessary privileged containers
- Limiting exposed ports
- Reviewing mounted host directories
- Using least-privilege application users
- Scanning images for vulnerabilities
- Configuring firewall rules
- Avoiding unnecessary Docker socket exposure
- Keeping secrets out of Dockerfiles and images
A particularly important rule is:
Never expose the Docker daemon's control interface to the Internet without understanding the security consequences.
๐ What Can You Do After Installing Docker?
Once Docker is running, Ubuntu becomes an excellent platform for experimenting with modern infrastructure.
You can run:
Development
- Python applications
- Node.js
- Java
- Go
- .NET
Databases
- PostgreSQL
- MySQL
- MongoDB
- Redis
DevOps
- Jenkins
- GitLab
- Prometheus
- Grafana
AI/ML
- Ollama
- Jupyter
- AI APIs
- GPU-enabled workloads
- Model-serving infrastructure
Infrastructure
- Nginx
- Apache
- Kubernetes components
- Message queues
- Microservices
This makes Docker particularly useful for developers, SREs, cloud engineers and system administrators.
๐ Complete Installation Command List
For quick reference:
# Update Ubuntu
sudo apt update && sudo apt upgrade -y
# Install dependencies
sudo apt install -y ca-certificates curl gnupg lsb-release
# Add Docker GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Add Docker repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package index
sudo apt update
# Install Docker
sudo apt install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
# Verify
sudo systemctl status docker
docker --version
docker compose version
# Optional: use Docker without sudo
sudo usermod -aG docker $USER
newgrp docker
# Test
docker run hello-world๐ฏ Conclusion
Installing Docker on Ubuntu doesn't have to be complicated.
By using Docker's official APT repository, you can install Docker Engine, Docker CLI, containerd, Buildx and Docker Compose and quickly start running containers.
The basic workflow is:
Update Ubuntu
↓
Install Dependencies
↓
Add Docker GPG Key
↓
Add Docker Repository
↓
Install Docker
↓
Verify Installation
↓
Run hello-world
↓
Start Building Containers ๐Once docker run hello-world successfully displays "Hello from Docker!", your Ubuntu system is ready for the next stage of container-based development.
The real power of Docker begins after installation—when you start building images, creating Compose stacks, networking containers, managing persistent volumes, securing deployments, and integrating containers into CI/CD and cloud infrastructure.
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......