Master Docker: Install, Accelerate, and Manage Images on CentOS & Ubuntu
This guide provides step‑by‑step instructions for installing Docker on CentOS and Ubuntu, configuring accelerated image mirrors, managing Docker images—including listing, tagging, and removing—while covering essential commands, storage considerations, and best practices for both systemd and upstart environments.
Introduction
This article gives a detailed walkthrough of Docker installation, image acceleration, and image management on Linux distributions, primarily CentOS and Ubuntu.
Install Docker on CentOS
Ensure the kernel version is higher than 3.10, then run the following commands as root: uname -r Update the system and remove any old Docker packages:
sudo yum update</code>
<code>sudo yum remove docker docker-common docker-selinux docker-engineInstall required utilities:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2Add a repository (official, Alibaba Cloud, or Tsinghua University):
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo</code>
<code>sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</code>
<code>sudo yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repoInstall Docker CE: sudo yum install docker-ce Start Docker and enable it at boot:
sudo systemctl start docker</code>
<code>sudo systemctl enable dockerVerify the installation:
docker versionInstall Docker on Ubuntu
Docker CE supports Ubuntu 14.04 (Artful 17.10 Edge+), 16.04 LTS, and 14.04 LTS. Install prerequisites and remove old versions: sudo apt-get remove docker docker-engine Use the official convenience script for quick installation:
curl -fsSL get.docker.com -o get-docker.sh</code>
<code>sudo sh get-docker.sh --mirror AzureChinaCloudStart and enable Docker:
sudo systemctl enable docker</code>
<code>sudo systemctl start dockerDocker Image Accelerators
Because pulling images from Docker Hub can be slow in China, configure a registry mirror. Examples include Docker’s official China mirror, Alibaba Cloud, and DaoCloud. The article shows how to set up the Alibaba Cloud mirror.
For upstart‑based systems (e.g., Ubuntu 14.04, Debian 7): edit /etc/default/docker and add:
DOCKER_OPTS="--registry-mirror=https://xxxx.mirror.aliyuncs.com"Then restart Docker: sudo service docker restart For systemd‑based systems (Ubuntu 16.04+, Debian 8+, CentOS 7): create or edit /etc/docker/daemon.json:
{
"registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}Reload and restart Docker:
sudo systemctl daemon-reload</code>
<code>sudo systemctl restart dockerManaging Docker Images
Pull an image: docker pull ubuntu:16.04 List images: docker image ls Show only IDs: docker image ls -q Filter images (e.g., dangling, by repository, before a tag):
docker image ls -f dangling=true</code>
<code>docker image ls ubuntu</code>
<code>docker image ls -f since=mongo:3.2Delete images by ID, name, or digest:
docker image rm 501</code>
<code>docker image rm centos</code>
<code>docker image rm node@sha256:b4f0e0bde...Understanding Untagged vs Deleted : Untagged removes a tag; Deleted removes the underlying image data when no tags remain.
Special Considerations for CentOS/RHEL
CentOS/RHEL lack native UnionFS drivers, so Docker defaults to the devicemapper driver with a loop‑LVM setup, which has performance and stability drawbacks. It is recommended to configure direct‑LVM for better reliability and space utilization.
Images and Layers
Docker images consist of multiple layers. The size shown by docker image ls is the uncompressed size on disk, which can differ from the compressed size shown on Docker Hub. Layers are shared between images, so total disk usage may be lower than the sum of listed sizes.
Dangling images ( <none>) appear after a newer version of a tag is pulled; they can be removed with: docker image prune Intermediate layers are shown with -a and should not be removed manually because other images may depend on them.
Running a Container
Example of running an interactive Ubuntu container: docker run -it --rm ubuntu:16.04 bash Inside the container you can inspect the OS release file:
cat /etc/os-releaseConclusion
Following this guide enables you to install Docker on major Linux distributions, accelerate image pulls with regional mirrors, and efficiently manage images and containers using Docker’s command‑line tools.
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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
