docker-archive/docker-snap

How to config the daemon settings?

Closed this issue ยท 12 comments

In systemd case, we usually modify the /etc/systemd/system/..../docker.service file, such as change ExecStart= line; or create/modify /etc/docker/daemon.json file, but how to do it in this docker snap setup?

Hey @twang2218
In snappy world, docker daemon can't access the /etc/docker folder under the strict confinement as there're only a few readable/writable paths that app can access
https://docs.snapcraft.io/reference/confinement

Therefore we left a patch to make daemon config file accessible for docker daemon
https://github.com/docker/docker-snap/blob/master/patches/snappy-etc-docker.patch
So in general, the location of the actual daemon config file is under the following folder
/var/snap/docker/current/etc/docker
That's where the daemon config file located which you can utilize to edit daemon setting file.
Also, you need root privilege to enter the above folder and create/edit daemon config file.
Hopefully, that works for you.

Gary

Hi, Gary, Thanks for your response.

It's great that we can use /var/snap/docker/current/etc/docker/daemon.json to config the docker daemon. But I realize that the /var/snap/docker/current is a symlink to the latest version, so if I update the snap, will the daemon.json be copied to the newer version? And is there a way to append some arguments to the dockerd executable? Thanks.

Tao

That's an interesting question, and the answer is no. Since SNAP_DATA (/var/snap/docker/current) is not intended to be sharing across revisions of a snap, so here comes SNAP_COMMON
https://docs.snapcraft.io/reference/env

Re: append some arguments to dockerd executable?
Sorry, we've not supported it yet.

@jdstrand @psftw @lool
Probably, we need to rethink to move daemon config dir from
$SNAP_DATA + "/etc/docker" (/var/snap/docker/current/etc/docker)
to ->
$SNAP_COMMON + "/etc/docker" (/var/snap/docker/common/etc/docker)
so that we can keep the daemon config consistently accessible for upcoming iteration versions.
How do you think about that?

@tianon It's ok to use daemon.json, I just prefer using argument because it's easy to debug. Just ps -ef | grep dockerd, then all configurations are there. For daemon.json case, there isn't a command to list all the effective configuration for docker daemon, and I even don't know whether dockerd read the daemon.json I create, or which daemon.json it tried to read. And docker info is not including all the settings. I tried to submit a PR to dump the configurations in the log, but it's closed as it might leak sensitive information in the logs.

But, currently, I'm fine with daemon.json, as most information I needed are in the docker info now. such as registry-mirror was added to docker info since 1.13. So, it's ok for me to use daemon.json.

lool commented

Actually for configuration which has a chance of breaking on upgrade, $SNAP_DATA is a better location.

On upgrades, $SNAP_DATA is copied from old revision to new revision โ€“ but it's not copied back on downgrade (revert).

daemon.json sounds like a small file which is cheap to copy and might (accidentally) contain forwards or backwards-incompatible changes, so it seems a good thing to use the copy mechanism between upgrades.

$SNAP_COMMON would work, but it means that care must be taken that the format is always forwards and backwards compatible as to allow reverts/downgrades.

the location of the actual daemon config file is under the following folder
/var/snap/docker/current/etc/docker
That's where the daemon config file located which you can utilize to edit daemon setting file.
Also, you need root privilege to enter the above folder and create/edit daemon config file.
Hopefully, that works for you.

@adglkh this is not working for me the way you describe.

To troubleshoot, I deliberately created a daemon.json that would conflict with the command-line options:

root@golbez:~# cat /var/snap/docker/current/etc/docker/daemon.json 
{
  "pidfile": "/var/snap/docker/179/run/dockerXXX.pid"
}

If I manually force it to use this file, it immediately fails with the expected conflict:

root@golbez:~# snap run docker.dockerd --config-file=/var/snap/docker/current/etc/docker/daemon.json
unable to configure the Docker daemon with file /var/snap/docker/current/etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: pidfile: (from flag: /var/snap/docker/179/run/docker.pid, from file: /var/snap/docker/179/run/dockerXXX.pid)

but if I don't specify --config-file on the command line, either launching manually with snap run docker.dockerd or by letting systemd launch it in the usual way, no conflict occurs, which proves it's not reading the file at all.

root@golbez:~# systemctl start snap.docker.dockerd
root@golbez:~# ps -ef | grep dockerd
root      8453     1  9 10:45 ?        00:00:00 dockerd -G docker --debug --log-level=debug --exec-root=/var/snap/docker/179/run/docker --graph=/var/snap/docker/common/var-lib-docker --pidfile=/var/snap/docker/179/run/docker.pid

Am I doing something obviously wrong? I'm relatively new to both docker and snap, but need to use daemon.json to change the default bridge network to avoid an IP conflict.

root@golbez:~# snap list
Name         Version     Rev   Tracking  Developer     Notes
atom         1.26.0      148   stable    snapcrafters  classic
core         16-2.32.3   4407  stable    canonical     core
docker       17.06.2-ce  179   stable    docker-inc    -
hello-world  6.3         27    stable    canonical     -

same issues, currently is not possible to use a different runtime like kata containers

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.

@anonymouse64
Great! In my Ubuntu 18.04.1 LTS Server with snap docker, editing /var/snap/docker/current/config/daemon.json allow me to use zfs filesystem which means editing that file just works as editing /etc/docker/daemon.json when using deb docker.

Thanks man

Hi @anonymouse64 good job!

Could you point me to the code?

Thank you!

psftw commented

Closing all issues and pull requests since this repo is getting archived (see notice at the top of README).