Centos7安装docker

一.安装docker-ce

参见https://yeasy.gitbooks.io/docker_practice/install/centos.html

#更新yum软件源缓存,并安装 docker-ce。
sudo yum install docker-ce docker-ce-cli containerd.io
#获取安装脚本
curl -fsSL get.docker.com -o get-docker.sh
#执行安装
sudo sh get-docker.sh --mirror Aliyun
# 启动并设置自启动
sudo systemctl enable docker
sudo systemctl start docker
# 添加当前用户到docker用户组
sudo usermod -aG docker $USER
#重新登录后生效
#重新登录后生效
#重新登录后生效

测试docker

docker run --rm hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

二.安装docker-compose

sudo yum install docker-compose

[注意]如果失败了

# 使用如下命令,更新一下源,然后再安装
yum install -y epel-release

实在不行,手动安装

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

三.修改docker配置

1.创建或修改`daemon.json`文件

sudo vim /etc/docker/daemon.json

2.新增如下配置

{
    "registry-mirrors": [
        "https://registry.dockermirror.com",
        "https://qiojqnqv.mirror.aliyuncs.com",
    	"https://hub-mirror.c.163.com",
    	"https://mirror.baidubce.com"
      ],
    "log-driver": "json-file",
    "log-opts": {
        "max-size":"100m", 
        "max-file":"3"
    }
}

3.重载daemon-reload

sudo systemctl daemon-reload

4.重启docker

sudo systemctl restart docker