centos7 安装Docker及docker-compose

一、安装Docker

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

1
2
3
4
5
6
7
8
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

2. 安装系统依赖及源

a. 安装依赖包

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

b. 设置源

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

3. 安装Docker CE(社区版)

a. 安装最新版

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

b. 启动Docker

1
$ sudo systemctl start docker

c. 设置开机自动启动

1
$ sudo systemctl enable docker

测试安装是否成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[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. 运行一下命令,安装最新版本

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. 执行命令

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

3. 测试安装是否成功

1
2
3
4
5
[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
Author: Binger Chen
Link: http://www.kekefund.com/2019/03/18/docker-install/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.