How to Install Docker on CentOS 7: A Complete Step-by-Step Guide
This tutorial walks you through checking system requirements, using one‑click scripts or manual steps to install Docker CE on CentOS 7, starting the service, verifying with a hello‑world container, and provides common Docker commands for ongoing use.
Background
After handling several projects that rely on Docker, the author notes that Docker has become essential in the cloud‑native era and shares a full installation guide for Linux.
Docker and System Versions
Docker is offered as Community Edition (CE) and Enterprise Edition (EE); the guide uses CE. It runs on 64‑bit CentOS 7/8 with a kernel version of at least 3.10.
Check the OS version with lsb_release -a or cat /etc/redhat-release. Example output shows CentOS 7. Verify the kernel with cat /proc/version, uname -a or uname -r; the sample shows a kernel of 3.10.x, which satisfies Docker’s requirement.
Automated Docker Installation
Docker provides a one‑click script, and the Chinese service DaoCloud offers an alternative.
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun curl -sSL https://get.daocloud.io/docker | shRunning either command installs Docker automatically.
Manual Docker Installation
Uninstall old versions (optional)
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
docker-ceSet up the repository
Install required utilities first:
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2Add the official Docker repo:
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repoFor faster access in China, replace the URL with mirrors such as Aliyun or Tsinghua:
Aliyun: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Tsinghua: https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
Install Docker Engine
sudo yum install -y docker-ce docker-ce-cli containerd.ioIf only the engine is needed, a minimal install works: yum install -y docker-ce After installation Docker is present but not started.
Start Docker
sudo systemctl start dockerVerify the installation by pulling and running the hello‑world image:
# docker pull hello-world
# docker run hello-worldA successful run prints a message confirming that Docker works correctly.
Reload daemon: systemctl daemon-reload Restart Docker: systemctl restart docker or service docker restart Stop Docker: systemctl stop docker or
docker service stopRemove Docker
yum remove docker-ceDelete all images, containers and configuration files:
rm -rf /var/lib/dockerCommon Docker Commands
Search images: docker search IMAGE_NAME Pull image: docker pull IMAGE_NAME List running containers: docker ps List all containers: docker ps -a Remove container: docker rm CONTAINER_ID List images: docker images Remove image: docker rmi IMAGE_ID Start stopped container: docker start CONTAINER_ID Stop container: docker stop CONTAINER_ID Restart container: docker restart CONTAINER_ID Run a new container interactively: docker run -it ubuntu /bin/bash Enter a running container: docker exec -it CONTAINER_ID /bin/bash Additional options are available via docker help.
Senior Brother's Insights
A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.
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.
