1. Install Docker on CentOS7 (simple and detailed)

1. Configuration requirements

Architecture diagram of docker

System: Centos7

Note: The commands in this article use the root user to log in and execute them. If you are not root, you must add sudo in front of all commands.

update yum package

yum -y update         升级所有包同时也升级软件和系统内核;​
yum -y upgrade        只升级所有包,不升级软件和系统内核

Uninstall the old version (if installed before)

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2. Install Docker

  1. install package

Install the required software packages, yum-util provides yum-config-manager function, and the other two are devicemapper driver dependencies

yum install -y yum-utils device-mapper-persistent-data lvm2
  1. set yum source

yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo(中央仓库)

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo(阿里仓库)
  1. install docker

yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

Note: You can choose other versions to install

One-click script installation

// 安装docker
curl -fsSL https://get.docker.com -o get-docker.sh  && \
 bash get-docker.sh
 
Ubuntu 和 Debian 系统可以使用这套脚本安装:

官方给的命令  
curl -sSL https://get.docker.com/ | sh

 国内一键安装 sudo curl -sSL https://get.daocloud.io/docker | sh
 
阿里云的
curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh -

// docker-compose安装
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

First query the installed version of docker

yum list docker-ce --showduplicates | sort -r

Install the version you want to use

yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io docker-compose-plugin
  1. Start docker and add boot self-start

启动      systemctl start docker
加入自启   systemctl enable docker
  1. View docker version


docker version       #显示docker的版本信息
docker -v            #显示docker的简单版本信息
docker info          #显示docker的系统信息,包裹镜像和容器的数量
docker 命令 --help   #帮助命令
  1. test hello-world

docker run hello-world
  1. uninstall docker

卸载依赖
yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
删除资源目录
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
  1. Configure Mirror Accelerator

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://k3tod9qx.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

Guess you like

Origin blog.csdn.net/lzyaks/article/details/128515319