Environment:
- OS: debian 8.0.0-amd64, ubuntu-15.04, 16.04
- Docker: 1.x.x
Procedure:
I changed /etc/default/docker
to add a private docker registry, then I restarted docker service and finally tried to pull some image.
$ cat /etc/default/docker
DOCKER_OPTS="--insecure-registry mydocker-registry.net:5000"
$ service docker restart
$ docker pull mydocker-registry.net:5000/testdb
FATA[0000] Error: v1 ping attempt failed with error: Get https://mydocker-
registry.net:5000/v1/_ping: dial tcp: lookup mydocker-registry.net: no
such host. If this private registry supports only HTTP or HTTPS with an
unknown CA certificate, please add `--insecure-registry mydocker-
registry.net:5000` to the daemon's arguments. In the case of HTTPS, if
you have access to the registry's CA certificate, no need for the flag;
simply place the CA certificate at /etc/docker/certs.d/mydocker-
registry.net:5000/ca.crt
A ps
output shows nothing about DOCKER_OPTS environment var.
$ ps auxwww|grep docker
root 6919 0.0 0.1 331076 19984 ? Ssl 10:14 0:00 /usr/bin/docker -d -H fd://
Question:
According to docker documentation the way to use a private registry is through DOCKER_OPTS in /etc/default/docker
. Why, after doing that, it does not take effect in this environment?
Notes:
- The private registry hostname is correctly resolved by the DNS.
Systemd is really not designed for appending options to ExecStart or Environment. The best and also most platform-independent way is to use the
/etc/docker/daemon.json
configuration file.Behold:
Things seem to have changed in
Ubuntu 16.04
using docker1.12.x
. Based on the updated documentationAdd
DOCKER_OPTS="-g /mnt/somewhere/else/docker/ --storage-driver=overlay2"
to/etc/default/docker
Edit file
/lib/systemd/system/docker.service
Then execute:
Recommended Way Docker 17.xx +
There are a number of ways to configure the daemon flags and environment variables for your Docker daemon. The recommended way is to use the platform-independent
daemon.json
file, which is located in/etc/docker/
on Linux by default.So, for configuring insecure registries, do the following:
Set the following flag in the
/etc/docker/daemon.json
file:Restart Docker
Easier each time!
Previously Recommended Way with Docker 1.12
According to docker documentation, The recommended way to configure the daemon flags and environment variables for your Docker daemon is to use a systemd drop-in file.
So, for this specific case, do the following:
Create a file called
/etc/systemd/system/docker.service.d/private-registry.conf
with the following content:Flush changes:
Restart Docker:
Voila!
Not recommended way
Edit file
/lib/systemd/system/docker.service
Then execute
Verify that
/etc/default/docker
is loadedThat's it.
Ubuntu specific solution to insecure-registry via DOCKER_OPTS
Because...
...ships with...
...(Specifically:
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS
) you can do a hybrid approach combining the [chosen answer's] "Recommended Way" and the use ofDOCKER_OPTS
to keep from blowing over the-H fd://
option if you were to redefineExecStart
I had a similar challenge. When I started looking to begin moving some systems from Ubuntu 14.04 to Ubuntu 16.04. My goal was to use one dockerd configuration file with dockerd flags (DOCKER_OPTS) for both Ubuntu 16.04 (systemd) and Ubuntu 14.04 (Upstart) other than /etc/docker/daemon.json. I chose not to use /etc/docker/daemon.json for docker daemon configuration because json does not support comments.
I wanted a systemd design to use an override file, which only modifies dockerd flags. It uses the default Docker systemd configuration file (/lib/systemd/system/docker.service) for other Docker settings. Another objective was to customise systemd on each system after each change or boot.
It solves my challenge. It may help you.
https://github.com/BradleyA/docker-scripts/tree/master/dockerd-configuration-options
Systemd based systems do not read /etc/default configurations, you have to put those in /etc/systemd now, see also docker bug docker bug #12926
There is an official documentation on the Docker site now, refer to Control and configure Docker with systemd.
You should never directly hack the service files for configuration.
Tested and works on Arch and Debian based systems - I had to include the option to ignore any obsolete EnvironmentFile directives, though (see also linked Docker reference, but I didn't spot it at first and thought it was not needed):