centos7 安装Docker及docker-compose

一、安装Docker

1. 卸载旧版本(若未安装过Docker,可跳过)

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine \
                  docker-selinux  \
                docker-engine-selinux \
                container-selinux \
                docker-ce \
                docker-ce-cli

2. 安装系统依赖及源

a. 安装依赖包

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

b. 设置源

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

3. 安装Docker CE(社区版)

a. 安装最新版

$ sudo yum install docker-ce docker-ce-cli containerd.io

b. 安装指定版本

# 查看所有可用的版本
[root@VM_32_86_centos ~]# yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
 
#安装
$ sudo yum install docker-ce-18.09.3 docker-ce-cli-18.09.3 containerd.io

c. 启动Docker

$ sudo systemctl start docker

d. 设置开机自动启动

$ sudo systemctl enable docker

测试安装是否成功

[root@VM_19_15_centos ~]# docker version
Client:
 Version: 18.09.3
 API version: 1.39
 Go version: go1.10.8
 Git commit: 774a1f4
 Built: Thu Feb 28 06:33:21 2019
 OS/Arch: linux/amd64
 Experimental: false

Server: Docker Engine - Community
 Engine:
  Version: 18.09.3
  API version: 1.39 (minimum version 1.12)
  Go version: go1.10.8
  Git commit: 774a1f4
  Built: Thu Feb 28 06:02:24 2019
  OS/Arch: linux/amd64
  Experimental: false

https://docs.docker.com/install/linux/docker-ce/centos/

二、安装docker-compose

1. 运行一下命令,安装最新版本

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

要安装指定版本, 替换1.23.2为你选择的版本

2. 执行命令

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

3. 测试安装是否成功

[root@VM_19_15_centos ~]# docker-compose version
docker-compose version 1.23.2, build 1110ad01
docker-py version: 3.6.0
CPython version: 3.6.7
OpenSSL version: OpenSSL 1.1.0f 25 May 2017

你可能感兴趣的:(centos7 安装Docker及docker-compose)