docker配置文件


本人在初學docker的時候,感覺對於docker的配置文件有點搞不定,一會是/etc/sysconfig/docker,一會是/etc/docker/daemon.json,一會是/etc/systemd/system/docker.service.d目錄下,更有甚者是/usr/lib/systemd/system/docker.service。

比如配置一個INSECURE-REGISTRY,就可以在/etc/sysconfig/docker文件里添加,也可以在/etc/docker/daemon.json文件里添加。特別的,這兩個文件里的格式還不一樣!!

這些配置文件到底是什么關系呢?是怎么被docker加載生效的呢?下文簡單講述他們之間的關系及docker的一些配置文件規划。

  • 拿到一台主機,用systemctl status docker查看docker的運行狀態:

可以看到,加載的其實是/usr/lib/systemd/system/docker.service這個文件。

  • 個人認為docker也發現自己的配置文件太分散了,所以搞了一個/etc/docker/daemon.json,但是這個文件默認是不存在的,需要我們手動的去創建(不知道為什么不默認幫我們創建好,就算幫用戶創建一個空的文件也行啊!)。

有了這個文件,我們一些常規的配置,都可以統一在這個文件里進行設置了,如下是/etc/docker/daemon.json的所有配置項:

{
    "authorization-plugins": [],
    "data-root": "",
    "dns": [],
    "dns-opts": [],
    "dns-search": [],
    "exec-opts": [],
    "exec-root": "",
    "experimental": false,
    "storage-driver": "",
    "storage-opts": [],
    "labels": [],
    "live-restore": true,
    "log-driver": "",
    "log-opts": {},
    "mtu": 0,
    "pidfile": "",
    "cluster-store": "",
    "cluster-store-opts": {},
    "cluster-advertise": "",
    "max-concurrent-downloads": 3,
    "max-concurrent-uploads": 5,
    "default-shm-size": "64M",
    "shutdown-timeout": 15,
    "debug": true,
    "hosts": [],
    "log-level": "",
    "tls": true,
    "tlsverify": true,
    "tlscacert": "",
    "tlscert": "",
    "tlskey": "",
    "swarm-default-advertise-addr": "",
    "api-cors-header": "",
    "selinux-enabled": false,
    "userns-remap": "",
    "group": "",
    "cgroup-parent": "",
    "default-ulimits": {},
    "init": false,
    "init-path": "/usr/libexec/docker-init",
    "ipv6": false,
    "iptables": false,
    "ip-forward": false,
    "ip-masq": false,
    "userland-proxy": false,
    "userland-proxy-path": "/usr/libexec/docker-proxy",
    "ip": "0.0.0.0",
    "bridge": "",
    "bip": "",
    "fixed-cidr": "",
    "fixed-cidr-v6": "",
    "default-gateway": "",
    "default-gateway-v6": "",
    "icc": false,
    "raw-logs": false,
    "allow-nondistributable-artifacts": [],
    "registry-mirrors": [],
    "seccomp-profile": "",
    "insecure-registries": [],
    "no-new-privileges": false,
    "default-runtime": "runc",
    "oom-score-adjust": -500,
    "node-generic-resources": ["NVIDIA-GPU=UUID1", "NVIDIA-GPU=UUID2"],
    "runtimes": {
        "cc-runtime": {
            "path": "/usr/bin/cc-runtime"
        },
        "custom": {
            "path": "/usr/local/bin/my-runc-replacement",
            "runtimeArgs": [
                "--debug"
            ]
        }
    }
}
  • 所有的涉及到配置文件修改后,需要重啟docker服務,讓其加載生效。

# systemctl daemon-reload

# systemctl restart docker

  • daemon.json里的內容記不住怎么辦?

# man dockerd


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM