1.卸载老版本

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

2.更新源(可选步骤)

cd /etc/yum.repos.d/

sudo mv CentOS-Base.repo CentOS-Base.repo.bak

sudo wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum clean all
yum makecache

3.安装Docker(https://docs.docker.com/install/linux/docker-ce/centos/)

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

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

$ sudo yum install docker-ce

4.启动停止Docker服务(可选步骤)

$ sudo systemctl start/stop/restart docker

设置开机自启动

systemctl enable docker

5.使用阿里云Docker镜像加速仓库(可选步骤)

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://t492znuq.mirror.aliyuncs.com",
    "http://ef017c13.m.daocloud.io",
    "https://registry.docker-cn.com"
  ],
  "insecure-registries": [
    "127.0.0.1:15000",
    "172.17.0.1:15000",
    "172.18.1.1:15000"
  ],
  "log-driver":"json-file",
  "log-opts": {"max-size":"100m", "max-file":"3"}
}
EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

6.开启Docker远程连接(可选步骤)

修改配置文件 sudo vim /usr/lib/systemd/system/docker.service

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock


重启服务 sudo systemctl daemon-reloadsudo systemctl restart docker

7.安装Portainer管理Docker(https://www.portainer.io/install.html)

$ sudo docker volume create portainer_data

$ sudo docker run -d -p 9000:9000 --restart=always --name=portainer -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

首次进入 http://10.7.1.74:9000/ 设置用户名密码 (admin/600998jzt)

8.Docker使用示例(安装Redis)

sudo docker pull redis:5.0.0

-- 对外端口16379,容器端口6379
sudo docker run --name redis5 -d -p 16379:6379 redis:5.0.0



Docker镜像仓库

文档更新时间: 2019-12-01 13:52   作者:lizw