- 容器启动过程四个步骤
- daemon.json 配置介绍
- 配置项注意点:
- graph: 该关键字未来将被弃用,可以采用 “data-root” 替代
- storage-driver: 存储驱动,即分层文件系统
- insecure-registries: 不安全的docker registries,即使用http协议推拉镜象
- https://registry.docker-cn.com)的地址">registry-mirrors: 加速站点,一般可以使用阿里、网易云、docker中国(https://registry.docker-cn.com)的地址
- bip: 指定docker bridge地址(不能以.0结尾),生产中建议采用 172.xx.yy.1/24,其中xx.yy为宿主机ip后四位,方便定位问题
- 若启动失败,查看 /var/log/message 日志排错
docker 是一个典型的C/S架构
Docker在2017年以前时使用大版本号+小版本号来名,在2017年之后,采用YY.MM.N-xx格式,如 19.03.1-ce表示2019年3月份的第2个ce版本。以CentOS 7安装docker-ce版本为例
[root@docker-24-20 ~]# uname -r # 确认内核版本,要求大于3.83.10.0-862.el7.x86_64[root@docker-24-20 ~]# wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo[root@docker-24-20 ~]# yum install -y docker-ce # 安装docker-ce[root@docker-24-20 ~]# vim /etc/docker/daemon.json # 初始化配置{"graph": "/data/docker","storage-driver": "overlay2","insecure-registries": ["registry.access.redhat.com","quay.io"],"registry-mirrors": ["https://q2gr04ke.mirror.aliyuncs.com"],"bip": "172.24.20.1/24","exec-opts": ["native.cgroupdriver=systemd"],"log-opts": {"max-size":"32M", "max-file":"2"},"live-restore": true}[root@docker-24-20 ~]# mkdir -p /data/docker[root@docker-24-20 ~]# systemctl start docker && systemctl enable docker[root@docker-24-20 ~]# ip addr show dev docker0 # 确认IP地址3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group defaultlink/ether 02:42:e7:6b:2d:f6 brd ff:ff:ff:ff:ff:ffinet 172.24.20.1/24 brd 172.24.20.255 scope global docker0valid_lft forever preferred_lft forever~]# docker version # 查看版本[root@docker-24-20 ~]# docker container run --rm hello-world # 测试docker是否运行正常Unable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world1b930d010525: Pull completeDigest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064Status: Downloaded newer image for hello-world:latestHello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(amd64)3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://hub.docker.com/For more examples and ideas, visit:https://docs.docker.com/get-started/
容器启动过程四个步骤
- Docker客户端联系Docker服务端。
2. Docker服务端从Docker中心拉取“hello-world”映像。
3. Docker服务端(用新拉的镜像)创建了一个新的容器,该容器运行可执行文件(脚本),生成您当前读取的输出。
4. Docker服务端将信息流推到Docker客户端,由客户端展示在你的终端。 ```bashdaemon.json 配置介绍
{ “graph”: “/data/docker”, “storage-driver”: “overlay2”, “insecure-registries”: [“registry.access.redhat.com”,”quay.io”], “registry-mirrors”: [“https://q2gr04ke.mirror.aliyuncs.com“], “bip”: “172.24.38.1/24”, “exec-opts”: [“native.cgroupdriver=systemd”], “live-restore”: true }
配置项注意点:
graph: 该关键字未来将被弃用,可以采用 “data-root” 替代
storage-driver: 存储驱动,即分层文件系统
insecure-registries: 不安全的docker registries,即使用http协议推拉镜象
registry-mirrors: 加速站点,一般可以使用阿里、网易云、docker中国(https://registry.docker-cn.com)的地址
bip: 指定docker bridge地址(不能以.0结尾),生产中建议采用 172.xx.yy.1/24,其中xx.yy为宿主机ip后四位,方便定位问题
若启动失败,查看 /var/log/message 日志排错
```bash[root@docker-24-20 ~]# docker info # Docker 信息查看Client:Debug Mode: falseServer:Containers: 0 # 容器数量Running: 0Paused: 0Stopped: 0Images: 1 # 镜像数量Server Version: 19.03.5 # server 版本Storage Driver: overlay2Backing Filesystem: xfs # 宿主机上的底层文件系统Supports d_type: trueNative Overlay Diff: trueLogging Driver: json-fileCgroup Driver: systemd # Cgroups 驱动Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: b34a5c8af56e510852c35414db4c1f4fa6172339runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657init version: fec3683Security Options:seccompProfile: defaultKernel Version: 3.10.0-862.el7.x86_64 # 宿主机的相关信息Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 2Total Memory: 3.685GiBName: docker-24-20ID: ASZO:NO2O:EJ2W:WGN5:MWAL:MBMP:TURI:WKNC:YUPS:E4E2:MATG:MXV3Docker Root Dir: /data/docker # docker 数据存储目录Debug Mode: falseRegistry: https://index.docker.io/v1/ # registry 地址Labels:Experimental: falseInsecure Registries:quay.ioregistry.access.redhat.com127.0.0.0/8Registry Mirrors: # 加速站点https://q2gr04ke.mirror.aliyuncs.com/Live Restore Enabled: trueWARNING: bridge-nf-call-iptables is disabled # 当前两个warn需要设置内核模块WARNING: bridge-nf-call-ip6tables is disabled
Docker pull配置代理
部分场景中,下载国外镜像非常慢,因此可以配置相关代理进行加速,方法如下:
配置宿主机代理
1. 找到 Lantern 的代理服务器的http(s)监听地址,以当前宿主机 127.0.0.1:9768 为例2. 配置windows端口的转发,将所有10.4.7.1的10080端口转发至 127.0.0.1:9768netsh interface portproxy add v4tov4 listenaddress=10.4.7.1 listenport=10080 connectaddress=127.0.0.1 connectport=97683. 配置windows防火墙策略,允许 10.4.7.0/24 网段访问 10.4.7.1:100804. 配置Linux机器的http和https代理[root@centos-7-50 ~]# export http_proxy="10.4.7.1:10080"[root@centos-7-50 ~]# export https_proxy="10.4.7.1:10080"5. 测试[root@centos-7-50 ~]# curl -I https://www.google.comHTTP/1.1 200 OKDate: Friday, 20-Mar-20 09:55:18 CSTKeep-Alive: timeout=58Content-Length: 0# 实验环境的虚拟机使用的是 10.4.7.0/24 的NAT网络,宿主机地址为 10.4.7.1
配置docker代理
root@ubuntu-7-61:~# mkdir /etc/systemd/system/docker.service.droot@ubuntu-7-61:~# vim /etc/systemd/system/docker.service.d/http-proxy.conf[Service]Environment="HTTP_PROXY=http://10.4.7.1:10080"root@ubuntu-7-61:~# systemctl daemon-reloadroot@ubuntu-7-61:~# systemctl restart dockerroot@ubuntu-7-61:~# docker info 2>&1 | grep -i proxyHTTP Proxy: http://10.4.7.1:10080
