0

I´m struggeling with the activation of Remote API for docker.

Already tried to set configuration by the following command:

DOCKER_OPTS="-H tcp://127.0.0.1:2375"

in following files:

/etc/default/docker

and

/etc/init.d/docker.conf

Then restarted daemon by pkill and started again by docker daemon & but still not working for me. What did I miss?

root@ubuntu:~# docker info
 Containers: 7
 Running: 1
 Paused: 0
 Stopped: 6
 Images: 24
 Server Version: 1.11.2
 Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 139
 Dirperm1 Supported: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins: 
 Volume: local
 Network: bridge null host
 Kernel Version: 4.2.0-36-generic
 Operating System: Ubuntu 14.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 7.78 GiB
 Name: ubuntu
enter code here
flyOWX
  • 215
  • 1
  • 2
  • 11

3 Answers3

2

Running docker daemon & by hand ignores all configuration files. Those files are referenced when you start Docker with the OS upstart commands, or an /etc/init.d/docker start. To bind to the port when starting by hand, you'd need to pass the argument there: docker daemon -H tcp://127.0.0.1:2375. Note that this allows anyone with access to the local network full root access on your machine.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • Nice, well to know. `/etc/init.d/docker start` starts with a process nr as output but still message _cannot connect to docker daemon_. Same message for `service docker (re)start` – flyOWX Jul 21 '16 at 06:56
1

Instead of changing the docker daemon config and having to restart it, you can use Sherpa to open up a path to the remote API via remote-proxy. Something like:

docker run -d \
--name sherpa \
-e CONFIG='[
    { 
        "Path" : "/",
        "Access": "allow",
        "Addresses": ["10.0.0.0/8"]
    }
]' \
-v /var/run/docker.sock:/tmp/docker.sock \
-p 4550:4550 \
djenriquez/sherpa --allow

would give you access on port 4550 and only accepts requests from source clients in the 10.0.0.0/8 space. You can customize all kinds of ACLs for the remote API also. You can run a docker run script on start up, if this is easier.

Checkout the introductory post here: https://www.linkedin.com/pulse/easily-enable-docker-remote-api-sherpa-dj-enriquez or directly to the repo here: https://hub.docker.com/r/djenriquez/sherpa/

Rao
  • 20,781
  • 11
  • 57
  • 77
1
  1. update /lib/systemd/system/docker.service
  • sudo vim /lib/systemd/system/docker.service in [Service] section, change the value of ExecStart to be:
  • ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 and save the file
  1. restart docker service:
  • sudo systemctl daemon-reload
  • sudo systemctl restart docker
  1. verify
    run one of the following commands:
  • ps aux | grep dockerd
    The expected result will look like below:
    root 4522 0.0 2.0 417112 81476 ? Ssl 20:36 0:00 /usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375

  • curl 127.0.0.1:2375/info The expected result will be a long json string

  • netstat -nlp
    The following will be shown:
    tcp6 0 0 :::2375 :::* LISTEN -

  • sudo docker -H tcp://127.0.0.1:2375 ps
    The running containers will be shown


Above works for Ubuntu 14.04
Juan Zhao
  • 11
  • 2