Is it possible to start multiple docker daemons on the same machine

Yes, it's perfectly possible to run two Docker daemons on a single host even without Docker Machine. As of Docker 18.09.0-ce, the following dockerd flags are the ones that could cause conflicts if two daemons used the defaults:

  -b, --bridge string       Attach containers to a network bridge
      --exec-root string    Root directory for execution state files (default "/var/run/docker")
      --data-root string    Root directory of persistent Docker state (default "/var/lib/docker")
  -H, --host list           Daemon socket(s) to connect to
  -p, --pidfile string      Path to use for daemon PID file (default "/var/run/docker.pid")
  • The default for --bridge is docker0, and if you're not using the default, you must create and configure the bridge manually (Docker won't create/manage it for you). More details below.

  • --exec-root is where container state is stored (default: /var/run/docker).

  • --data-root is where images are stored (default: /var/lib/docker).

  • --host specifies where the Docker daemon will listen for client connections. If unspecified, it defaults to /var/run/docker.sock.

  • --pidfile is where the process ID of the daemon is stored (default: /var/run/docker.pid).

So, as long as your two daemons use different values for these flags, you can run them on the same host. Example script (including network setup):

#!/bin/sh
## name: altdocker.sh
set -e -x

: ${bridge=altdocker}
: ${base=$HOME/$bridge}

# Set up bridge network:
if ! ip link show $bridge > /dev/null 2>&1
then
   sudo ip link add name $bridge type bridge
   sudo ip addr add ${net:-"10.20.30.1/24"} dev $bridge
   sudo ip link set dev $bridge up
fi

sudo dockerd \
  --bridge=$bridge \
  --data-root=$base.data \
  --exec-root=$base.exec \
  --host=unix://$base.socket \
  --pidfile=$base.pid

Example usage:

## in one terminal
$ env net=10.9.8.7/24 /bin/sh altdocker.sh
# ... log output ...

## in another terminal
$ docker -H unix://$HOME/altdocker.socket run --rm -i -t alpine sh
/ # echo hereiam
hereiam

Updated for changes from Docker 1.9.1 to 18.09.0-ce, in case anyone is using a very old version:

┌───────────────┬─────────────┐
│ 1.9.1         │ 18.09.0-ce  │
├───────────────┼─────────────┤
│ docker daemon │ dockerd     │
│ -g / --graph  │ --exec-root │
└───────────────┴─────────────┘

Great question! It is possible to start a Docker daemon inside a container. In that container you would be able to start more containers. This way you can run docker daemons with different settings on the same host machine.

Checkout this project: https://github.com/jpetazzo/dind. It provides a Docker image that contains Docker itself, just as you require.

Tags:

Docker