I need to start docker daemon with some command line arguments in Ubuntu, and when doing so manually, the following command works fine:
$ dockerd -H fd:// -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock
The above command makes it possible for me to integrate docker with PhpStorm's docker plugin, and configure containers from there. Docker daemon starts listening to TCP port 2375 that is used by PhpStorm in my case.
I need to start docker daemon automatically with the same parameters, and it seems that there is a lot of controversial information about it. I tried many different solutions, including changing /etc/default/docker or /etc/systemd/system/docker.service.d/docker.conf and editing DOCKER_OPTS parameter there.
How can I run docker daemon with the above command line arguments automatically in Ubuntu 16.04?
Among other solutions that didn't work, here is one that did work. It includes changing the docker.service definition:
# edit the following file
# /lib/systemd/system/docker.service
# ...
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock
# ...
After changing that file, run systemctl daemon-reload to apply the changes made to docker.service file, followed by service docker restart.
Another solution does not require changes to docker.service file, which can be later replaced after upgrading docker package, breaking the configuration. It requires creating or editing of /etc/docker/daemon.json file:
{
"hosts": [
"fd://",
"unix:///var/run/docker.sock",
"tcp://127.0.0.1:2375"
]
}
Restarting docker service after these changes are made also makes docker daemon listen to TCP connections on port 2375 or connections using Unix socket.
Note that the above solutions cannot be used together: only one of them should be used to prevent conflicts.