一看必會系列:DOCKER_OPTS參數不生效問題

來源:本站原創 Docker 超過216 views圍觀 0條評論

 

docker.service

配置docker.service的時候,EnvironmentFile的文件默認配置了/etc/sysconfig/docker(基本配置)、/etc/sysconfig/docker-storage(存儲)、/etc/sysconfig/docker-network(網絡),我們想要/etc/default/docker 生效,我們就需要添加EnvironmentFile=-/etc/default/docker,讓后在ExecStart這個配置中,添加引用的參數$DOCKER_OPTS,下面就是我的配置文件/usr/lib/systemd/system/docker.service

#修改配置文件
vi /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer

[Service]
Type=notify
NotifyAccess=all
KillMode=process
#添加我們自定義的配置文件
EnvironmentFile=-/etc/default/docker #添加配置文件,(-代表ignore error)
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
          –add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          –default-runtime=docker-runc \
          –exec-opt native.cgroupdriver=systemd \
          –userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY \
          $DOCKER_OPTS #需要引用的參數,也是網卡設定參數
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
MountFlags=slave

[Install]
WantedBy=multi-user.target
EnvironmentFile=-/etc/default/docker

修改以后,需要重載,然后重啟服務才可以使用/etc/default/docker里定義的DOCKER_OPTS參數

#重載
systemctl daemon-reload
#重啟docker服務
service docker restart

docker環境配置文件

vi /etc/sysconfig/docker
DOCKER_OPTS="-b=br0"

#或者直接寫數據
echo ‘DOCKER_OPTS="-b=br0"’ >> /etc/default/docker
docker自定義網橋

#安裝網橋工具
yum install bridge-utils 

#添加網橋
brctl addbr br0

#查看網橋
brctl show

#設定網橋地址和子網掩碼
ifconfig br0 192.168.110.1 netmask 255.255.255.0

#設定網橋
echo ‘DOCKER_OPTS="-b=br0"’ >> /etc/default/docker

#配置docker
vi /usr/lib/systemd/system/docker.service
#添加我們自己的配置文件
EnvironmentFile=-/etc/sysconfig/docker
#應用參數
ExecStart=/usr/bin/dockerd-current \
               –add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
                –default-runtime=docker-runc \
                –exec-opt native.cgroupdriver=systemd \
                –userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
                $OPTIONS \
                $DOCKER_STORAGE_OPTIONS \
                $DOCKER_NETWORK_OPTIONS \
                $ADD_REGISTRY \
                $BLOCK_REGISTRY \
                $INSECURE_REGISTRY \
                $DOCKER_OPTS #添加網橋的參數

#重載
systemctl daemon-reload
#重啟docker服務
service docker restart

修改成功 后的網橋信息

查看網橋數據

 

------------以下是正確姿勢

網橋修改成功后,網卡的網段和子網掩碼都修改了

[email protected]:~# docker run –rm  –name b5 busybox ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
104: [email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
    link/ether 02:42:c0:a9:6e:02 brd ff:ff:ff:ff:ff:ff
    inet 192.169.110.2/24 brd 192.169.110.255 scope global eth0
       valid_lft forever preferred_lft forever
[email protected]:~#

[email protected]:~# !ps
ps -ef |grep docker
root     26972     1  0 02:02 ?        00:00:00 /usr/bin/dockerd -H fd:// -b=br0                                                      
root     27376 19710  0 02:05 pts/0    00:00:00 grep –color=auto docker                                                              
[email protected]:~#

vim "/lib/systemd/system/docker.service"
[Service]                                                                                                                             
Type=notify                                                                                                                           
# the default is not to use systemd for cgroups because the delegate issues still                                                     
# exists and systemd currently does not support the cgroup feature set required                                                       
# for containers run by docker                                                                                                        
#ExecStart=/usr/bin/dockerd -H fd://                                                                                                  
EnvironmentFile=-/etc/default/docker                                                                                                  
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS                                                                                      
ExecReload=/bin/kill -s HUP $MAINPID                                                                                                  
TimeoutSec=0                                                                                                                          
RestartSec=2                                                                                                                          
Restart=always  

文章出自:CCIE那點事 http://www.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=4076轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
  • 相關文章
  • 為您推薦
  • 各種觀點
?
暫時還木有人評論,坐等沙發!
發表評論

您必須 [ 登錄 ] 才能發表留言!

?
?
萌宠夺宝游戏