Skip to content

mbentley/docker-in-docker

Repository files navigation

mbentley/docker-in-docker

Table of Contents

Image Tags

For a complete list of published images, see the list of tags on Docker Hub. For each major release, the specific Docker Enterprise bugfix versions are also available and can be found via Docker Hub.

Build images (optional)

Expand for more details

The images are published to Docker Hub so you do not need to build them unless you want to.

Note: the images build on each other. The ce tag is its own build and has no other dependencies other than ubuntu:20.04. The ce-systemd tag builds from ce. The ce-systemd-ssh tag builds from ce-systemd. So if you want to build ce-systemd-ssh, you should first build ce, then ce-systemd, and finally ce-systemd-ssh. This process is to re-use layers. I also recommend using docker build buildx as just docker build fails to re-use some layers that have no changed.

  • Docker CE (stable)

    docker buildx build \
      --build-arg DOCKER_VER="$(wget -q -O - https://api.github.com/repos/moby/moby/releases/latest | jq -r .tag_name)" \
      -f Dockerfile.ce \
      -t mbentley/docker-in-docker:ce \
      .
    
  • Docker CE (with systemd)

    docker buildx build \
      -f Dockerfile.ce-systemd \
      -t mbentley/docker-in-docker:ce-systemd \
      .
    
  • Docker CE (with systemd + ssh)

    docker buildx build \
      -f Dockerfile.ce-systemd-ssh \
      -t mbentley/docker-in-docker:ce-systemd-ssh \
      .
    

Prerequisites

  • Docker for Mac installed
  • Must have the following ports available on your host:
    • 1000 - TCP connection to a single Docker engine (or whatever you specify)
    • 1001, 1002, 1003 - TCP connection to Docker engines for Swarm mode (or whatever you specify)

Single engine

  1. Start engine

    docker run -d \
      --init \
      --name docker \
      --hostname docker \
      --restart unless-stopped \
      --privileged \
      -p 127.0.0.1:1000:2375 \
      -v /lib/modules:/lib/modules:ro \
      -v docker-root:/root \
      -v docker-etc-docker:/etc/docker \
      -v docker-var-lib-docker:/var/lib/docker \
      -v docker-etc-cni:/etc/cni \
      -v docker-opt-cni:/opt/cni \
      -v docker-usr-libexec-kubernetes:/usr/libexec/kubernetes \
      -v docker-var-lib-kubelet:/var/lib/kubelet \
      -v docker-var-log:/var/log \
      --tmpfs /run \
      -e MOUNT_PROPAGATION="/" \
      mbentley/docker-in-docker \
      dockerd -s overlay2 -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
    
  2. Communicate with that engine

    docker -H tcp://localhost:1000 info
    
  3. Check version

    docker -H tcp://localhost:1000 version
    
  4. Destroy the Engine

    docker kill docker
    docker rm docker
    docker volume rm docker
    

Swarm mode cluster

  1. Create 3 engines

    for ENGINE_NUM in {1..3}
    do
      docker run -d \
        --init \
        --name docker${ENGINE_NUM} \
        --hostname docker${ENGINE_NUM} \
        --restart unless-stopped \
        --privileged \
        -p 127.0.0.1:100${ENGINE_NUM}:2375 \
        -v /lib/modules:/lib/modules:ro \
        -v docker${ENGINE_NUM}-root:/root \
        -v docker${ENGINE_NUM}-var-lib-docker:/var/lib/docker \
        -v docker${ENGINE_NUM}-etc-docker:/etc/docker \
        -v docker${ENGINE_NUM}-etc-cni:/etc/cni \
        -v docker${ENGINE_NUM}-opt-cni:/opt/cni \
        -v docker${ENGINE_NUM}-usr-libexec-kubernetes:/usr/libexec/kubernetes \
        -v docker${ENGINE_NUM}-var-lib-kubelet:/var/lib/kubelet \
        -v docker${ENGINE_NUM}-var-log:/var/log \
        --tmpfs /run \
        -e MOUNT_PROPAGATION="/" \
        mbentley/docker-in-docker \
        dockerd -s overlay2 -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
    done
    
  2. Create a new Swarm

    docker -H tcp://localhost:1001 swarm init
    
  3. Get the worker join token and command

    TOKEN=$(docker -H tcp://localhost:1001 swarm join-token worker -q)
    JOIN_COMMAND="swarm join --token ${TOKEN} $(docker container inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' docker1):2377"
    
  4. Join engine 2

    docker -H tcp://localhost:1002 ${JOIN_COMMAND}
    
  5. Join engine 3

    docker -H tcp://localhost:1003 ${JOIN_COMMAND}
    
  6. Check status

    docker -H tcp://localhost:1001 node ls
    
  7. Destroy Swarm cluster

    docker kill docker1 docker2 docker3
    docker rm docker1 docker2 docker3
    docker volume rm docker1 docker2 docker3
    

About

Run one or many Docker daemons inside Docker as containers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages