moby: DOCKER_OPTS do not work in config file /etc/default/docker

I have changed /etc/default/docker with DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock" (docker version 1.4.1 in ubuntu 14.04), but it do not take any effect for me. It seems that docker do not read this initital config file because I found export http_proxy enviroment do not work too.

Only sudo docker -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -d works.

It really confused me!

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 25
  • Comments: 56 (23 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve also encountered this problem (Debian Jessie 8.0, lxc-docker=1.6.2). After a look around at the configuration files in /lib/systemd/system/, it seems that the Docker configuration file (/lib/systemd/system/docker.service) is not using /etc/default/docker at all. 😦 The problem is solved by adding an EnvironmentFile directive and modifying the command line to include the options from the file, e.g.

[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target docker.socket
Requires=docker.socket

[Service]
EnvironmentFile=-/etc/default/docker
ExecStart=/usr/bin/docker -d $DOCKER_OPTS -H fd://
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity

[Install]
WantedBy=multi-user.target

I edited /lib/systemd/system/docker.service to look like the above, ran systemctl daemon-reload, and then restarted the Docker service. This time, it properly launched with the options set in DOCKER_OPTS in my /etc/default/docker.

Again, I’m on Debian Jessie 8.0 with lxc-docker=1.6.2, so YMMV.

@zepalmer, as the latest version of the documentation suggests (http://docs.master.dockerproject.org/articles/systemd/), the proper way to edit systemd service file is to create a file in /etc/systemd/system/docker.service.d/<something>.conf and only override the directives you need. The file in /lib/systemd/system/docker.service is “reserved” for the package vendor.

Using /etc/docker/daemon.json instead of /etc/default/docker solved my issue! This comments for those who scrolls to the last post 👅

@carloscds Don’t use /etc/default/docker. It’s used only by upstart, which is not used by Ubuntu since 16.04.

Use /etc/docker/daemon.json, which is documented here: https://docs.docker.com/engine/reference/commandline/dockerd/#/linux-configuration-file

This tripped me up a lot on Ubuntu 15.04 using Docker 1.8.0 experimental via the shell script install process. My assumption is the apt repository package does not provide a proper docker systemd unit file yet?

I ended up having to do a double ExecStart in my override file to clear the original else it would complain about two ExecStart’s on a oneshot.

I.e. in /etc/systemd/system/docker.service.d/docker.conf

[Service]
EnvironmentFile=-/etc/default/docker
ExecStart=
ExecStart=docker -d $DOCKER_OPTS ...

If you use options that need expansion, e.g.: DOCKER_OPTS="-g $(readlink -f /var/lib/docker)" then this might help:

[ ! -e /etc/systemd/system/docker.service.d/ ] && mkdir -p /etc/systemd/system/docker.service.d/
cat << 'EOF' > /etc/systemd/system/docker.service.d/docker.conf
# Load /etc/default/docker from SystemD init script
# References: 
#  https://github.com/docker/docker/issues/9889#issuecomment-120927382
#  https://gist.github.com/nickjacob/9909574

[Service]
# This line is sufficient if DOCKER_OPTS variable does not have to be expanded:
#EnvironmentFile=-/etc/default/docker
# Use this line to expand DOCKER_OPTS variable:
ExecStartPre=/bin/sh -c ". /etc/default/docker && /bin/systemctl set-environment DOCKER_OPTS=\"$DOCKER_OPTS\""

ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS

EOF

systemctl daemon-reload 
service docker restart

Correct, the /etc/default/docker file is only used on systems using “upstart” and “SysVInit”, not on systems using systemd.

This is also mentioned at the top of the file; https://github.com/docker/docker/blob/44fe8cbbd174b5d85d4a063ed270f6b9d2279b70/contrib/init/sysvinit-debian/docker.default#L1

You don’t define “DOCKER_OPTS”. In the old upstart config this is essentially what was happening:

# /etc/default/docker
DOCKER_OPTS="--insecure-registry 1.2.3.4 -s overlay"
# upstart config
source /etc/default/docker
exec docker daemon "$DOCKER_OPTS"

DOCKER_OPTS was not some special env var that Docker uses, it’s just set in one file and consumed by the init script in another file and inserted as an inline argument to the docker command.

/etc/docker/daemon.json is the hard-coded default location for daemon configuration in Docker. To do the equivalent config as above you would put this in /etc/docker/daemon.json:

{
    "insecure-registries": ["1.2.3.4"],
    "storage-driver": "overlay"
}

When docker starts, it reads this file and loads the configuration.

@carloscds did you take the time to read the discussion above before posting your question?

( I was initially looking for how to add DOCKER_OPTS="--iptables=false" )

Sum-up for Ubuntu 18.04 / Docker Server Version: 20.10.6

{
         "iptables": false,
 	 "ip6tables": false
}

@eric-tucker it helps for people that arrive on these issues through Google search, and may not be aware of the way things work.

Having gone down this road twice here’s my take for Debian Jessie:

Debian GNU/Linux 8 (jessie) / Docker version 1.12.3

vi /lib/systemd/system/docker.service

Change this line:

     ExecStart=/usr/bin/dockerd --label=[co.kwk.dc=sj] -H fd://

systemctl daemon-reload service docker restart

Check it docker info

Would be great if /etc/default/docker file wasn’t installed on systemd setups.

@thaJeztah That link fixed my issue too. I could clearly see that adding things to /etc/sysconfig/docker was not doing anything but I wasn’t really sure the best way to fix it.

Is there anyone I could notify to let them know the docs are wrong on this page: https://docs.docker.com/engine/articles/configuring/

Or at least put in a link for systemd (Red Hat) installs so others can figure it out faster: http://docs.docker.com/engine/articles/systemd/#custom-docker-daemon-options

@mattelacchiato no they were not. systemd has a built-in method called ‘drop-ins’ to handle customizing unit files.

https://coreos.com/os/docs/latest/using-systemd-drop-in-units.html