93

From docs:

The default location of the configuration file on Linux is /etc/docker/daemon.json

But I don't have it on my fresh docker installation:

# 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

7 Answers 7

113

The default config file path on Linux is /etc/docker/daemon.json like you said, but it doesn't exist by default. You can write one yourself and put additional docker daemon configuration stuff in there instead of passing in those configuration options into the command line. You don't even have to do dockerd --config-file /etc/docker/daemon.json since that's the default path, but it can be useful to make it explicit for others who are inspecting the system.

Also ensure that any configuration you set in /etc/docker/daemon.json doesn't conflict with options passed into the command line evocation of dockerd. For reference:

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.

7
  • 11
    So, it's perfectly normal not having daemon.json after a fresh installation of docker-ce, right? Apr 4, 2018 at 15:47
  • 2
    +1 @floatingpurr sounds normal to me - on the basis that 1) my installation doesn't have it by default and 2) I think the thinking behind it is to use the 'discovery' approach whereby docker discovers the presence of this optional file. By having it not there, we know for certain that default settings will be used. Jun 6, 2018 at 12:54
  • 7
    That's ridiculous. Dockers documentation says you have to CHANGE a flag in that file (iptables). It's either a documentation problem or a bug in docker that the file is missing.
    – John
    Jul 21, 2018 at 15:11
  • 8
    how do you view what config a currently running docker daemon is pointing to?
    – red888
    Jul 27, 2018 at 13:08
  • 2
    According to dockerd documentation: The default location of the configuration file on Linux is /etc/docker/daemon.json. The --config-file flag can be used to specify a non-default location. (see docs.docker.com/engine/reference/commandline/dockerd)
    – Mugen
    Oct 11, 2018 at 6:22
8

If you have installed Docker as part of installation of Ubuntu, then Docker is installed as a snap.

The config can be found in /var/snap/docker/current/config/daemon.json.

Refer to https://github.com/docker-archive/docker-snap/issues/22#issuecomment-423361607

Summary:

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.

This now seems to be present in 'stable'. I am using Ubunu 20.04 and I found daemon.json in /var/snap/docker/current/config/daemon.json.

I changed the 'log-driver' to 'local' and this was picked up by docker after restarting it:

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
1
  • 1
    User-specific config.json in Ubuntu with snap is located in ~/snap/docker/current/.docker/config.json
    – Jarek
    Mar 23, 2022 at 18:59
4

Based on @huu answer I searched for the specific reference in the docs.

Notice the sentences in bold below.


Reference 1: From the Configure the Docker daemon section:

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.


Reference 2: From the Enable debugging section

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.

  1. 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.

  2. ....

2
  • Creating a file do not impose that it is not existing by default.
    – astef
    Jan 28, 2021 at 19:12
  • I just add references to the docs which basically say that if it doesn't exist - create it (:
    – RtmY
    Jan 28, 2021 at 20:57
2

Docker 19+, Mac

Config file is now available in ~/.docker/daemon.json

2

I am on ubuntu 20.04. If it doesn't exist it can be created in the /etc/docker directory . Worked for me.

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Feb 15, 2022 at 18:54
1

For me on mac it was located in /Users/your-username/.docker

4
  • Dude, that's the folder where docker-cli configs reside, not docker daemon's Oct 15, 2020 at 7:16
  • I disagree with @IuriiVasylenko above, ~/.docker/daemon.json is exactly where I found it as well.
    – chahu418
    Apr 7, 2021 at 22:11
  • @chahu418 that's dead horse, in recent versions, apparently you're right though: stackoverflow.com/a/57221633/4046235 Apr 8, 2021 at 10:03
  • the question is about ubuntu
    – rok
    Sep 20, 2021 at 10:48
0

I am now using M1 MacOS, and the installed latest Docker Desktop. For that you can find daemon.json by open "Docker Desktop" > "Preferences" > "Docker Engine" > edit the texteditor under "Configure the Docker daemon by typing a json Docker daemon configuration file" > "Apply & Restart".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.