卸载

执行如下命令,卸载当前系统的 docker

  1. sudo yum remove docker docker-client docker-client-latest \
  2. docker-common docker-latest docker-latest-logrotate \
  3. docker-logrotate docker-engine

更新 yum

  1. # 升级所有的包,同时也升级软件和系统内核
  2. sudo yum -y update

安装 Docker

安装需要的软件包和设置 yum 源

  1. sudo yum install -y yum-utils device-mapper-persistent-data lvm2
  2. # 设置yum源
  3. sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum 查看可用版本

  1. sudo yum list docker-ce --showduplicates | sort -r

yum 安装 Docker

这里需要选择docker-ce相关版本的docker安装

  1. sudo yum -y install docker-ce-18.06.3.ce

检查安装版本

执行如下命令:

  1. sudo docker version

结果如下

  1. Client:
  2. Version: 18.06.3-ce
  3. API version: 1.38
  4. Go version: go1.10.3
  5. Git commit: d7080c1
  6. Built: Wed Feb 20 02:26:51 2019
  7. OS/Arch: linux/amd64
  8. Experimental: false
  9. Server:
  10. Engine:
  11. Version: 18.06.3-ce
  12. API version: 1.38 (minimum version 1.12)
  13. Go version: go1.10.3
  14. Git commit: d7080c1
  15. Built: Wed Feb 20 02:28:17 2019
  16. OS/Arch: linux/amd64
  17. Experimental: false

设置开机自启动并启动 Docker

  1. sudo systemctl enable docker && systemctl start docker

设置镜像源

如果嫌原镜像源速度太慢,可以换成国内各大厂或机构的镜像源。

  1. # 1.创建Docker配置文件夹
  2. sudo mkdir -p /etc/docker
  3. # 2.创建配置:daemon.json
  4. sudo tee /etc/docker/daemon.json <<-'EOF'
  5. {
  6. "registry-mirrors": ["https://6m7no14o.mirror.aliyuncs.com"],
  7. "exec-opts": ["native.cgroupdriver=systemd"],
  8. "log-driver": "json-file",
  9. "log-opts": {
  10. "max-size": "100m"
  11. },
  12. "storage-driver": "overlay2",
  13. "storage-opts": [
  14. "overlay2.override_kernel_check=true"
  15. ]
  16. }
  17. EOF
  18. # 3.重启Docker
  19. sudo systemctl daemon-reload && systemctl restart docker

安装 docker-compose

版本发布地址 https://github.com/docker/compose/releases 官方安装教程 https://docs.docker.com/compose/install/

下载二进制文件安装

  1. sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  2. # 或者
  3. wget https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

授权

  1. sudo chmod +x /usr/local/bin/docker-compose

检查安装版本

  1. docker-compose --version