Search code examples
dockerboot2docker

Enabling Remote API in Docker on Mac OS X (boot2docker)


I can't seem to figure out how to enable the remote API when using boot2docker. I am trying to use dockerode as follows:

Docker = require('dockerode')
docker = new Docker(socketPath: "/var/run/docker.sock")

container = docker.getContainer('<my_container_id>')

container.inspect (err, data) ->
  debug data

Data is null, despite there being a container with the id ''. I suspect this is because there is no /var/run/docker.sock on the OS X host, and that I would need to use something like:

var docker2 = new Docker({host: 'http://192.168.1.10', port: 3000});

... but can't figure out how to configure boot2docker or docker in the VirtualBox VM to enable access via http or tcp.


Solution

  • Docker, as configured by Boot2Docker, supports remote access on port 2375 from the host OSX machine by default; this is what is set up when it tells you to do export DOCKER_HOST=tcp://192.168.59.103:2375

    If you want to access the port from another machine you need to configure VirtualBox networking to route traffic to that port. This could be done by port forwarding with this command:

    VBoxManage modifyvm "boot2docker-vm" --natpf1 "guestssh,tcp,,2375,,2375"
    

    Then the address to use in your new Docker code is the IP address of your Mac.

    You can also configure this in the VirtualBox GUI under boot2docker-vm/settings/network/advanced/port forwarding.

    See VirtualBox docs.

    Note, as described here that this now allows anyone with IP access to your machine to control your Docker installation, which may be a security concern.