Installing Docker and Docker Compose on CentOS 7
Overview
This section outlines the process of installing Docker on CentOS 7, covering both online and offline installation methods. Only CentOS 7 and later versions with kernel 3.10 or higher are supported.
Online Installation of Docker
-
Check the system version:
cat /etc/redhat-release -
Install required dependencies:
yum install -y yum-utils device-mapper-persistent-data lvm2 -
Add the Docker repository:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -
Update package cache:
yum makecache fast -
Install Docker Community Edition:
yum -y install docker-ce -
Start the Docker service:
systemctl start docker -
Verify the installation:
docker version -
Download and install Docker Compose:
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose -
Set execute permissions:
chmod +x /usr/local/bin/docker-compose -
Confirm Docker Compose installation:
docker-compose version -
Enable Docker to start at boot:
systemctl enable docker
Offline Instalaltion of Docker
-
Obtain the offline installation package, typically named
centos-local.tgz(contact for access). -
Upload the package to the root directory of the server.
-
Extract the archive:
cd /root tar -xvzf centos-local.tgz -
Install createrepo:
cd /root/docker-ce-local rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm -
Create a local repository configuration file:
vi /etc/yum.repos.d/docker-ce-local.repoWith the following content:
[docker-ce-local] name=Local Yum baseurl=file:///root/docker-ce-local/ gpgcheck=1 gpgkey=file:///root/docker-ce-local/gpg enabled=1 -
Generate repository metadata:
createrepo /root/docker-ce-local yum makecache -
Install Docker CE without GPG verification:
yum install docker-ce --nogpgcheck -
Start and verify Docker:
systemctl start docker docker version -
Enable auto-start on boot:
systemctl enable docker -
Copy Docker Compose binary:
cp /root/docker-ce-local/docker-compose /usr/bin/ -
Set execution rights:
chmod +x /usr/bin/docker-compose -
Validate Docker Compose:
docker-compose version