docker 的 daemon.json 在哪里? (丢失的)
Where's docker's daemon.json? (missing)
来自docs:
The default location of the configuration file on Linux is
/etc/docker/daemon.json
但我的新 docker 安装中没有它:
# docker --version
Docker version 17.03.1-ce, build c6d412e
# ls -la /etc/docker/
total 12
drwx------ 2 root root 4096 Apr 28 17:58 .
drwxr-xr-x 96 root root 4096 Apr 28 17:58 ..
-rw------- 1 root root 244 Apr 28 17:58 key.json
# lsb_release -cs
trusty
如您所说,Linux 上的默认配置文件路径是 /etc/docker/daemon.json
,但默认情况下不存在。您可以自己编写一个并在其中放置额外的 docker 守护进程配置内容,而不是将这些配置选项传递到命令行中。您甚至不必执行 dockerd --config-file /etc/docker/daemon.json
,因为这是默认路径,但对于正在检查系统的其他人来说,将其明确化可能很有用。
还要确保您在 /etc/docker/daemon.json
中设置的任何配置不会与传递到 dockerd
命令行调用的选项冲突。供参考:
The options set in the configuration file must not conflict with options set via flags. The docker daemon fails to start if an option is duplicated between the file and the flags, regardless their value.
对我来说 mac 它位于 /Users/your-username/.docker
根据@huu的回答我在文档中搜索了具体的参考资料
注意下面以粗体显示的句子。
参考文献 1: 来自 Configure the Docker daemon 部分:
There are two ways to configure the Docker daemon:
Use a JSON configuration file. This is the preferred option, since it
keeps all configurations in a single place.
Use flags when starting
dockerd. You can use both of these options together as long as you
don’t specify the same option both as a flag and in the JSON file. If
that happens, the Docker daemon won’t start and prints an error
message.
To configure the Docker daemon using a JSON file, create a file at
/etc/docker/daemon.json
on Linux systems, or
C:\ProgramData\docker\config\daemon.json
on Windows. On MacOS go to
the whale in the taskbar > Preferences > Daemon > Advanced
.
参考文献 2: 来自 Enable debugging 部分
There are two ways to enable debugging. The recommended approach is to
set the debug key to true in the daemon.json file. This method works
for every Docker platform.
Edit the daemon.json file, which is usually located in /etc/docker/. You may need to create this file, if it does not yet
exist. On macOS or Windows, do not edit the file directly. Instead,
go to Preferences / Daemon / Advanced.
....
如果您在 Ubuntu 的安装过程中安装了 Docker,那么 Docker 将作为快照安装。
可以在 /var/snap/docker/current/config/daemon.json
中找到配置。
参考https://github.com/docker-archive/docker-snap/issues/22#issuecomment-423361607
总结:
anonymouse64 commented on 21 Sep 2018
Modifying the daemon.json file is now supported in the version of the snap
I have published in the edge channel. The daemon is now hard-coded to read
the config file for it's settings, so you can now edit the daemon.json
located in $SNAP_DATA/config/daemon.json (on Ubuntu for example $SNAP_DATA
is /var/snap/docker/current, it may be different on your distribution) and
then restart docker for the changes to take effect with:
sudo snap restart docker
You may switch the snap to the edge channel to test this by running:
sudo snap refresh docker --edge
The changes in the edge channel should show up in stable in a short while
if you don't wish to use edge.
现在似乎出现在 'stable' 中。我正在使用 Ubunu 20.04,我在 /var/snap/docker/current/config/daemon.json
.
中找到了 daemon.json
我将 'log-driver' 更改为 'local' 并在重新启动后被 docker 拾取:
docker info --format '{{.LoggingDriver}}'
json-file
nano /var/snap/docker/current/config/daemon.json
# added line: "log-driver":"local",
snap restart docker
docker info --format '{{.LoggingDriver}}'
local
我现在使用的是 M1 MacOS,并且安装了最新的 Docker 桌面。为此,您可以通过打开“Docker 桌面”>“首选项”>“Docker 引擎”> 在“通过键入json Docker 守护程序配置文件” > “应用并重新启动”。
Docker 19+, Mac
现在可以在 ~/.docker/daemon.json
中使用配置文件
我在 ubuntu 20.04。如果不存在,可以在 /etc/docker 目录中创建。为我工作。
来自docs:
The default location of the configuration file on Linux is /etc/docker/daemon.json
但我的新 docker 安装中没有它:
# docker --version
Docker version 17.03.1-ce, build c6d412e
# ls -la /etc/docker/
total 12
drwx------ 2 root root 4096 Apr 28 17:58 .
drwxr-xr-x 96 root root 4096 Apr 28 17:58 ..
-rw------- 1 root root 244 Apr 28 17:58 key.json
# lsb_release -cs
trusty
如您所说,Linux 上的默认配置文件路径是 /etc/docker/daemon.json
,但默认情况下不存在。您可以自己编写一个并在其中放置额外的 docker 守护进程配置内容,而不是将这些配置选项传递到命令行中。您甚至不必执行 dockerd --config-file /etc/docker/daemon.json
,因为这是默认路径,但对于正在检查系统的其他人来说,将其明确化可能很有用。
还要确保您在 /etc/docker/daemon.json
中设置的任何配置不会与传递到 dockerd
命令行调用的选项冲突。供参考:
The options set in the configuration file must not conflict with options set via flags. The docker daemon fails to start if an option is duplicated between the file and the flags, regardless their value.
对我来说 mac 它位于 /Users/your-username/.docker
根据@huu的回答我在文档中搜索了具体的参考资料
注意下面以粗体显示的句子。
参考文献 1: 来自 Configure the Docker daemon 部分:
There are two ways to configure the Docker daemon:
Use a JSON configuration file. This is the preferred option, since it keeps all configurations in a single place.
Use flags when starting dockerd. You can use both of these options together as long as you don’t specify the same option both as a flag and in the JSON file. If that happens, the Docker daemon won’t start and prints an error message.
To configure the Docker daemon using a JSON file, create a file at
/etc/docker/daemon.json
on Linux systems, orC:\ProgramData\docker\config\daemon.json
on Windows. On MacOS go to the whale in thetaskbar > Preferences > Daemon > Advanced
.
参考文献 2: 来自 Enable debugging 部分
There are two ways to enable debugging. The recommended approach is to set the debug key to true in the daemon.json file. This method works for every Docker platform.
Edit the daemon.json file, which is usually located in /etc/docker/. You may need to create this file, if it does not yet exist. On macOS or Windows, do not edit the file directly. Instead, go to Preferences / Daemon / Advanced.
....
如果您在 Ubuntu 的安装过程中安装了 Docker,那么 Docker 将作为快照安装。
可以在 /var/snap/docker/current/config/daemon.json
中找到配置。
参考https://github.com/docker-archive/docker-snap/issues/22#issuecomment-423361607
总结:
anonymouse64 commented on 21 Sep 2018
Modifying the daemon.json file is now supported in the version of the snap
I have published in the edge channel. The daemon is now hard-coded to read
the config file for it's settings, so you can now edit the daemon.json
located in $SNAP_DATA/config/daemon.json (on Ubuntu for example $SNAP_DATA
is /var/snap/docker/current, it may be different on your distribution) and
then restart docker for the changes to take effect with:
sudo snap restart docker
You may switch the snap to the edge channel to test this by running:
sudo snap refresh docker --edge
The changes in the edge channel should show up in stable in a short while
if you don't wish to use edge.
现在似乎出现在 'stable' 中。我正在使用 Ubunu 20.04,我在 /var/snap/docker/current/config/daemon.json
.
daemon.json
我将 'log-driver' 更改为 'local' 并在重新启动后被 docker 拾取:
docker info --format '{{.LoggingDriver}}'
json-file
nano /var/snap/docker/current/config/daemon.json
# added line: "log-driver":"local",
snap restart docker
docker info --format '{{.LoggingDriver}}'
local
我现在使用的是 M1 MacOS,并且安装了最新的 Docker 桌面。为此,您可以通过打开“Docker 桌面”>“首选项”>“Docker 引擎”> 在“通过键入json Docker 守护程序配置文件” > “应用并重新启动”。
Docker 19+, Mac
现在可以在 ~/.docker/daemon.json
我在 ubuntu 20.04。如果不存在,可以在 /etc/docker 目录中创建。为我工作。