Write by lyc at 2019-8-19
参考博文:
docker官方网站
docker官方文档
CentOS7 安装docker官方文档

1.安装前须知

  • docker-ce 版本:
    • CE(Community Edition: 社区版)
    • EE(Enterprise Edition: 企业版)
  • docker是基于内核研发的服务,内核版本很重要,ubuntu的高内核版本更好,意味着更强更稳定的性能,更少的BUG

2.Ubuntu 16.04 安装 docker-ce

ubuntu安装docker-ce

1
2
3
4
5
6
7
8
9
10
11
12
13
# Step 1: 安装必要的一些系统工具
$ sudo apt-get update
$ sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

# step 2: 安装GPG证书
$ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

# Step 3: 写入软件源信息
$ sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

# Step 4: 更新并安装 Docker-CE
$ sudo apt-get -y update
$ sudo apt-get -y install docker-ce

3.CentOS 7 安装 docker-ce

docker官方文档
这里使用阿里云镜像源安装,CentOS7安装docker-ce

1
2
3
4
5
6
7
$ yum remove docker* container-selinux
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ yum install -y yum-utils device-mapper-persistent-data lvm2
$ yum makecache fast
$ yum -y install docker-ce
$ systemctl enable docker
$ systemctl start docker

若提示 yum-config-manager 不存在,运行 yum install -y yum-utils.noarch

4.安装校验

1
2
3
$ docker run hello-world
$ docker version
$ docker info # 查看本机docker详细信息

5.为docker创建link

  • /var/lib/docker 是docker工程目录,里面包含了数据卷、日志、镜像、容器等,随docker服务启动自动生成。
  • docker工程目录默认是放在根下,因此很容易把操作系统根撑爆
  • 我们要为其创建软链接到挂在磁盘,防止该问题的发生。
1
2
3
4
5
$ systemctl stop docker
$ mkdir -p /data/docker_data/docker
$ cd /var/lib/ && rm -rf docker
$ ln -s /data/docker_data/docker /var/lib/
$ systemctl start docker