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

New ideas for time formatting in JavaScript toLocaleString()

Table of contents 1. Conventional ideas for time ...

Split and merge tables in HTML (colspan, rowspan)

The code demonstrates horizontal merging: <!DO...

Solve the abnormal error when building vue environment with webpack

Table of contents First, configure package.json T...

Detailed explanation of invisible indexes in MySQL 8.0

Word MySQL 8.0 has been released for four years s...

How to create a test database with tens of millions of test data in MySQL

Sometimes you need to create some test data, base...

nginx proxy_cache batch cache clearing script introduction

Preface: I used the official nginx proxy_cache as...

Analysis of multi-threaded programming examples under Linux

1 Introduction Thread technology was proposed as ...

Summary of MySQL usage specifications

1. InnoDB storage engine must be used It has bett...

Linux common text processing commands and vim text editor

Today, let's introduce several common text pr...

Difference between querySelector and getElementById methods in JS

Table of contents 1. Overview 1.1 Usage of queryS...

MySQL implements an example method of logging in without a password

Specific method: Step 1: Stop the mysql service /...

CentOS 7 installation and configuration tutorial under VMware10

If Ubuntu is the most popular Linux operating sys...