Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

And if it is possible, how would you configure each daemon - graph location, images location, etc?

like image 853
babbata Avatar asked Sep 01 '15 14:09

babbata


People also ask

Can I run multiple Docker containers at once?

Docker Compose is a tool that helps us overcome this problem and efficiently handle multiple containers at once. Also used to manage several containers at the same time for the same application. This tool can become very powerful and allow you to deploy applications with complex architectures very quickly.

Can Docker client and daemon run on different systems?

The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon.

How many Docker containers can I run locally?

Using this simple calculation, we can estimate that we can run about 1,000 containers on a single host with 10GB of available disk space.


2 Answers

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 │ └───────────────┴─────────────┘ 
like image 81
benizi Avatar answered Sep 21 '22 11:09

benizi


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.

like image 31
Jeroen Peeters Avatar answered Sep 23 '22 11:09

Jeroen Peeters