fra
fra

Reputation: 3858

Access docker remote API from container

I'm trying to access Docker remote API from within a container because I need to start other containers.

The host address is 172.19.0.1, so I'm using http://172.19.0.1:2375/images/json to get the list of images (from host, http://localhost:2375/images/json works as expected.

The connection is refused, I guess because Docker (for Windows) listens on 127.0.0.1 and not on 0.0.0.0.

I've tried to change configuration (both from UI and daemon.json) adding the entry:

"hosts": ["tcp://0.0.0.0:2375"]

but the daemon fails to start. How can I access the api?

Upvotes: 4

Views: 6214

Answers (3)

joseconstela
joseconstela

Reputation: 727

You could link the host's /var/run/docker.sock within the container where you need it. This way, you don't expose the Docker Remote API via an open port.

Be aware that it does provide root-like access to docker.

-v /var/run/docker.sock:/var/run/docker.sock

Upvotes: 1

Ivan Shibkih
Ivan Shibkih

Reputation: 41

You should use "tcp://host.docker.internal:2375" to connect to host machine from container. Please make sure that you can ping the "host.docker.internal" address https://github.com/docker/for-win/issues/1976

Upvotes: 0

qwerty
qwerty

Reputation: 2512

You can set DOCKER_OPTS in windows as below and try. In Windows, Docker runs inside a VM. So, you have to ssh into the VM and make the changes.

DOCKER_OPTS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock'

Check if it works for you.

Update :- To ssh into the VM (assuming default is the VM name you have created using Docker toolbox), enter the following command in the Docker Quickstart Terminal,

docker-machine ssh default

You can find more details here.

Upvotes: 1

Related Questions