Docker’s Real Value: Turning Environments into Reusable Descriptions
This guide explains Docker’s core benefit of making environments reproducible, walks through installing Docker from the official repository, configuring it for non‑root use, adding Compose, setting up registry mirrors, and deploying common containers like MySQL and Nginx.
Docker’s value is not merely avoiding manual environment setup; it turns an environment into a reusable description that runs consistently on a local machine, CI pipelines, and servers.
1. Install Docker
Installing via apt install docker.io often yields an outdated version, so the recommended approach is to use Docker’s official repository for up‑to‑date packages.
Add the official repository and install :
sudo apt update
sudo apt install ca-certificates curl gnupg
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
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
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginStart Docker :
sudo systemctl start docker
sudo systemctl enable docker # enable at boot2. Run Docker as a Non‑Root User (Important)
By default Docker commands require sudo. Adding the current user to the docker group removes this requirement, but the group effectively grants root‑like privileges, so use it cautiously on shared machines.
Add user to the group : sudo usermod -aG docker $USER Apply the new group membership : log out and back in, or run newgrp docker for a temporary effect.
Verify : docker run hello-world Successful output confirms the configuration.
3. Install Docker Compose
Docker Compose defines and runs multi‑container applications (e.g., a web service plus a database). It is now integrated as the docker compose plugin and is usually installed alongside Docker.
Verification:
docker compose version4. Configure Domestic Registry Mirrors
Pulling images from Docker Hub can be slow due to network constraints. Adding mirror registries speeds up downloads.
Edit the daemon configuration ( /etc/docker/daemon.json, create if missing): sudo nano /etc/docker/daemon.json Add mirror entries (examples using USTC, NetEase, or Alibaba Cloud mirrors):
{
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com"
]
}Restart Docker to apply changes:
sudo systemctl daemon-reload
sudo systemctl restart docker5. Common Docker Image Deployment Examples
Deploy a MySQL Database
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=YOUR_STRONG_PASSWORD -d mysql:8.0Deploy an Nginx Server
docker run --name some-nginx -p 8080:80 -d nginxAccess http://localhost:8080 to see the Nginx welcome page.
With Docker, the statement “it runs on my machine” becomes “it runs the same way on any machine” by codifying startup parameters, environment variables, volumes, and ports in a docker compose.yml file instead of manually typing long command lines.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ubuntu
Focused on Ubuntu/Linux tech sharing, offering the latest news, practical tools, beginner tutorials, and problem solutions. Connecting open-source enthusiasts to build a Linux learning community. Join our QQ group or channel for discussion!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
