Operations 22 min read

Master Docker: Install, Accelerate Images, and Manage Containers on Linux

This guide provides step‑by‑step instructions for installing Docker on CentOS and Ubuntu, configuring image accelerators for faster pulls, and using Docker commands to pull, run, list, and clean up images and containers, including tips for handling dangling and intermediate layers.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Docker: Install, Accelerate Images, and Manage Containers on Linux

Docker is a lightweight container platform that simplifies application deployment. This article walks through installing Docker on both CentOS and Ubuntu, configuring image acceleration, and managing Docker images and containers.

Installing Docker on CentOS

Check kernel version (must be >3.10) with uname -r.

Update packages: sudo yum update.

Remove old Docker packages:

sudo yum remove docker docker-common docker-selinux docker-engine

.

Install prerequisites:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

.

Configure yum repository (official, Alibaba Cloud, or Tsinghua mirrors) using sudo yum-config-manager --add-repo <repo_url>.

Install Docker CE: sudo yum install docker-ce (or list versions with yum list docker-ce --showduplicates | sort -r and install a specific version).

Start Docker and enable at boot: sudo systemctl start docker and sudo systemctl enable docker.

Verify installation with docker version.

Installing Docker on Ubuntu

Supported Ubuntu releases: 17.10, 16.04 LTS, 14.04 LTS (prefer LTS for production).

Remove old Docker packages: sudo apt-get remove docker docker-engine docker.io.

Use the official convenience script for quick installation:

curl -fsSL get.docker.com -o get-docker.sh && sudo sh get-docker.sh --mirror AzureChinaCloud

.

Start and enable Docker: sudo systemctl enable docker and sudo systemctl start docker.

Uninstall Docker: sudo apt-get autoremove docker-ce and delete the repository file in /etc/apt/sources.list.d.

Configuring Docker Image Accelerators

To speed up image pulls in China, configure a registry mirror. Example for Alibaba Cloud:

For upstart systems (Ubuntu 14.04, Debian 7), edit /etc/default/docker and set

DOCKER_OPTS="--registry-mirror=https://xxxx.mirror.aliyuncs.com"

, then restart Docker.

For systemd systems (Ubuntu 16.04+, Debian 8+, CentOS 7), create or edit /etc/docker/daemon.json with:

{
  "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}

and reload daemon with

sudo systemctl daemon-reload && sudo systemctl restart docker

.

Windows 10 and macOS also provide UI settings to add the same mirror URL.

Verify the mirror is active via docker info (look for Registry Mirrors).

Working with Docker Images

Pulling Images

Use docker pull [options] [registry/][repository][:tag]. Example: docker pull ubuntu:16.04 Shows layer download progress and final SHA256 digest.

Running Containers

Run an interactive shell in a container: docker run -it --rm ubuntu:16.04 bash Key flags: -i (interactive), -t (tty), --rm (auto‑remove after exit).

Listing Images

Basic list: docker image ls. Shows repository, tag, image ID, creation date, and size. Use filters and formats for specific needs:

Show only IDs: docker image ls -q.

Show dangling images: docker image ls -f dangling=true.

Show images created after a specific image: docker image ls -f since=mongo:3.2.

Custom format: docker image ls --format "{{.ID}}: {{.Repository}}".

Understanding Image Size

Docker Hub displays compressed size; docker image ls shows the expanded size on disk. Shared layers reduce actual disk usage.

Removing Images

Delete by ID, name, or digest:

docker image rm 501   # short ID
docker image rm centos   # repository:tag
docker image rm node@sha256:b4f0e0...

Docker first untags the image ( Untagged) and only deletes layers when no other tags reference them ( Deleted). Use docker image prune to remove all dangling images.

Advanced Cleanup

Combine listing and removal for batch operations, e.g., delete all Redis images: docker image rm $(docker image ls -q redis) or delete images older than a specific tag:

docker image rm $(docker image ls -q -f before=mongo:3.2)

Special Considerations for CentOS/RHEL

CentOS lacks native UnionFS drivers, so Docker defaults to the devicemapper driver with a loop‑back file, which has performance and stability drawbacks. For production, configure direct‑lvm storage to avoid the loop‑LVM issues and uncontrolled growth of /var/lib/docker/devicemapper/data. OverlayFS is back‑ported but not recommended for critical workloads.

By following these steps, you can install Docker, accelerate image pulls, and efficiently manage images and containers across various Linux distributions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerLinuxContainerCentOSUbuntuImage ManagementDevicemapperImage Accelerator
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.