Skip to content

Instantly share code, notes, and snippets.

@qoomon
Created December 17, 2018 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoomon/a431b2423e09b3d0f4bbcd624cf79c00 to your computer and use it in GitHub Desktop.
Save qoomon/a431b2423e09b3d0f4bbcd624cf79c00 to your computer and use it in GitHub Desktop.
Docker in Docker (dind)

docker network solution

BUILD_TAG="Dummy Job #$RANDOM"

echo "Create job network '$BUILD_TAG'"
job_network_id=$(docker network create "$BUILD_TAG" | tee $TTY)

echo "Start service container 'dind'"
docker run -d --privileged --net=${job_network_id} --network-alias dind docker:dind

echo "Start job container"
docker run -it \
  --net=${job_network_id} \
  -e DOCKER_HOST=tcp://dind:2375 \
  -e DOCKER_DRIVER=overlay2 \
  docker:git sh

docker run -it -v $PWD:/build bash

ls build

docker link solution (deprecated)

BUILD_TAG="Dummy Job #$RANDOM"

echo "Start service container 'dind'"
dind_containe_id=$(docker run --privileged -d docker:dind | tee $TTY)

echo "Start job container"
docker run --rm -it \
  --link ${dind_containe_id}:dind \
  -e DOCKER_HOST=tcp://dind:2375 \
  -e DOCKER_DRIVER=overlay2 \
  docker sh

docker run -v $PWD:/build bash

ls build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment