Docker: Modifying the DOCKER_OPTS parameter in /etc/default/docker does not take effect

Docker: Modifying the DOCKER_OPTS parameter in /etc/default/docker does not take effect

By default, /etc/default/docker configuration will not take effect. We need to manually add it to the docker environment settings. The file to be configured is /usr/lib/systemd/system/docker.service . We need to add EnvironmentFile=-/etc/default/docker . Then in the ExecStart configuration, add the referenced parameter $DOCKER_OPTS . When setting up the bridge, we added the DOCKER_OPTS parameter in /etc/default/docker , but the DOCKER_OPTS parameter did not take effect. The tutorials on the Internet were too bad. It might be because they were using the old version of Docker and the environment was different. After modifying it, it did not take effect at all. I was very upset at that time.

docker.service

When configuring docker.service, the EnvironmentFile file is configured by default with /etc/sysconfig/docker (basic configuration), /etc/sysconfig/docker-storage storage (storage), and /etc/sysconfig/docker-network (network). If we want /etc/default/docker to take effect, we need to add EnvironmentFile=-/etc/default/docker , and then add the referenced parameter $DOCKER_OPTS in the ExecStart configuration. The following is my configuration file /usr/lib/systemd/system/docker.service

#Modify the configuration file 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
#Add our custom configuration file EnvironmentFile=-/etc/default/docker #Add configuration file, (- stands for 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 #Parameters that need to be referenced, which are also the network card setting parameters 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

After the modification, you need to reload and then restart the service to use the DOCKER_OPTS parameters defined in /etc/default/docker

#Reload systemctl daemon-reload
#Restart the docker service service docker restart 

這里寫圖片描述

Docker environment configuration file

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

#Or write data directly echo 'DOCKER_OPTS="-b=br0"' >> /etc/default/docker

Docker custom bridge

#Install bridge tools yum install bridge-utils 

#Add a bridge brctl addbr br0

# View the bridge brctl show 

#Set the bridge address and subnet mask ifconfig br0 192.168.110.1 netmask 255.255.255.0

#Set up the bridge echo 'DOCKER_OPTS="-b=br0"' >> /etc/default/docker

#Configure Docker
vi /usr/lib/systemd/system/docker.service
#Add our own configuration file EnvironmentFile=-/etc/sysconfig/docker
#Application parameters 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 #Add bridge parameters #Reload systemctl daemon-reload
#Restart the docker service service docker restart

Bridge information after successful modification

這里寫圖片描述

View bridge data

這里寫圖片描述

After the bridge is modified successfully, the network segment and subnet mask of the network card are modified

這里寫圖片描述

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementation of modifying configuration files in Docker container
  • How to view the IP address of the Docker container
  • The whole process of deploying .net Core project using Docker on Linux server
  • Detailed installation and use of RocketMQ in Docker
  • Docker private repository management and deletion of images in local repositories
  • Example of how to upload a Docker image to a private repository
  • Detailed explanation of how to solve the problem that the docker container cannot access the host machine through IP
  • How to specify parameter variables externally in docker

<<:  Example of Vue routing listening to dynamically load the same page

>>:  3 methods to restore table structure from frm file in mysql [recommended]

Recommend

How to optimize MySQL index function based on Explain keyword

EXPLAIN shows how MySQL uses indexes to process s...

Should I abandon JQuery?

Table of contents Preface What to use if not jQue...

How to implement insert if none and update if yes in MySql

summary In some scenarios, there may be such a re...

CSS HACK for IE6/IE7/IE8/IE9/FF (summary)

Since I installed the official version of IE8.0, ...

How to debug loader plugin in webpack project

Recently, when I was learning how to use webpack,...

In-depth understanding of Vue's method of generating QR codes using vue-qr

Table of contents npm download step (1) Import (2...

Overview and differences between html inline elements and html block-level elements

Block-level element features : •Always occupies a ...

The qualities and abilities a web designer should have

Web design is an emerging marginal industry that c...

In-depth understanding of this in JavaScript

In-depth understanding of this in Js JavaScript s...

IIS7 IIS8 http automatically jumps to HTTPS (port 80 jumps to port 443)

IIS7 needs to confirm whether the "URL REWRI...

Detailed explanation of Angular data binding and its implementation

Table of contents Preface What is data binding? T...

About browser compatibility issues encountered and solutions (recommended)

Preface: Last Sunday, a senior asked me to help m...