共计 3897 个字符,预计需要花费 10 分钟才能阅读完成。
一、docker 安装
Docker 是管理容器的工具,Docker 不等于 容器。
1.1、docker yum 源设置
#step 1 download docker-ce.repo file
[root@zutuanxue ~]# wget https://download.docker.com/linux/centos/docker-ce.repo -P /etc/yum.repos.d/
--2019-11-14 20:46:09-- https://download.docker.com/linux/centos/docker-ce.repo
正在解析主机 download.docker.com (download.docker.com)... 13.35.50.117, 13.35.50.10, 13.35.50.93, ...
正在连接 download.docker.com (download.docker.com)|13.35.50.117|:443... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK
长度:2424 (2.4K) [binary/octet-stream]
正在保存至:“/etc/yum.repos.d/docker-ce.repo.1”100%[==================================================>] 2,424 --.-K/s 用时 0s
2019-11-14 20:46:09 (210 MB/s) - 已保存“/etc/yum.repos.d/docker-ce.repo.1”[2424/2424])
#step 2 change docker yum repo from tsinghua web
[root@zutuanxue ~]# sed -i 's#download.docker.com#mirrors.tuna.tsinghua.edu.cn/docker-ce#g' /etc/yum.repos.d/docker-ce.repo
1.2、docker 安装
1.2.1、卸载旧版本
[root@zutuanxue ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
1.2.2、安装 docker
[root@zutuanxue ~]# yum -y install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
[root@zutuanxue ~]# yum -y install docker-ce
1.2.3、启动 docker
[root@zutuanxue ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@zutuanxue ~]# systemctl start docker
1.3、验证启动
[root@zutuanxue ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2019-11-14 20:53:12 EST; 14s ago
Docs: https://docs.docker.com
Main PID: 1584 (dockerd)
Tasks: 12
Memory: 60.7M
CGroup: /system.slice/docker.service
└─1584 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.366007531-05:00" level=info msg="scheme \"unix\" not registered, fallback to defau...odule=grpc
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.366028377-05:00" level=info msg="ccResolverWrapper: sending update to cc: {[{unix:...odule=grpc
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.366036593-05:00" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.404043665-05:00" level=info msg="Loading containers: start."
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.547472878-05:00" level=info msg="Default bridge (docker0) is assigned with an IP a...P address"
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.588359436-05:00" level=info msg="Loading containers: done."
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.733704268-05:00" level=info msg="Docker daemon" commit=a872fc2f86 graphdriver(s)=o...on=19.03.3
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.733826656-05:00" level=info msg="Daemon has completed initialization"
11 月 14 20:53:12 zutuanxue systemd[1]: Started Docker Application Container Engine.
11 月 14 20:53:12 zutuanxue dockerd[1584]: time="2019-11-14T20:53:12.753929596-05:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
1.4、验证版本
[root@zutuanxue ~]# docker -v
Docker version 19.03.1, build 74b1e89
二、docker client 和 daemon 分离
docker client 与 daemon 分离
1、关闭 docker
[root@zutuanxue ~]# systemctl stop docker
2、修改 docker 启动方式,要求加载配置文件启动
[root@zutuanxue ~]# sed -i.bak '/^ExecStart=/c\ExecStart=\/usr\/bin\/dockerd' /usr/lib/systemd/system/docker.service
3、设置 docker 配置文件, 默认没有
设置允许监听地址和端口,以及 sock 文件连接
默认是使用 sock 方式连接,加 tcp://0.0.0.0:2375 可实现远程管理
[root@zutuanxue ~]# cat /etc/docker/daemon.json
{"hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]
}
4、重载 docker 服务、重启 docker 生效配置
[root@zutuanxue ~]# systemctl daemon-reload
[root@zutuanxue ~]# systemctl restart docker
5、查看 docker 的监听地址和端口
[root@zutuanxue ~]# netstat -ntpl |grep 2375
tcp6 0 0 :::2375 :::* LISTEN 21219/dockerd
6、客户端连接 docker daemon,执行命令
[root@zutuanxue ~]# docker -H 192.168.98.240 images
正文完
星哥玩云-微信公众号