Sign inSign up

sasol/dind4j

By sasol

Updated over 8 years ago

Docker in Docker image with Java 8 and docker-compose meant for running gradle builds.

Image
0

10K+

sasol/dind4j repository overview

dind4j

License Docker Pulls GitHub release

Docker in Docker image with Java 8 and docker-compose meant for running gradle builds.

Versioning

See releases on github to pick you version.

Info

This image is based on docker:1.13.0-dind so it contains docker and can be a host for child docker containers. There is also docker-compose and openjdk8 (in the same manner as official openjdk image) included.

Original Dind images runs dockerd in foreground so in order to use it you have to start linked image. This may be inconvenient especially when you need to mount some directories to child containers during build. This image allows to run commands along started docker daemon in background.

Because purpose of this image is to run builds, running them as root in container may lead to some side affects such as temporary files left by build with root ownership. This image allows to pass an user ID under which commands will be executed.

Examples

Building a gradle project

Assuming we are in gradle project directory we can do:

docker run --privileged \
    -e RUNASUID=$(id -u) \
    -w /build -v $(pwd):/build \
    --name dind4j-builder \
    --rm sasol/dind4j:latest \
    ./gradlew --no-daemon -gradle-user-home=.cache --project-cache-dir=.cache clean test

It will mount current directory as /build and run gradlew as user having id like current user. Dependencies and other cached by gradle files will land in .cache directory that will be found in projects directory. Add it to git ignore.

If RUNASUID variable is not set it will run as root.

Not running dockrd

DOCKERGUID is used to pass docker group id to container so that it will match host docker group, useful if you for some reason set SKIPDAEMON=true and mount /var/run/docker.sock. Container will add its internal 'user' user to a docker group with this id so it will match your docker group.

docker run  \
    -e RUNASUID=$(id -u) \
    -e DOCKERGUID=$(getent group docker | cut -d: -f3) \
    -e SKIPDAEMON=true \
    -v /var/run/docker.sock:/var/run/docker.sock \
    --rm -ti sasol/dind4j:latest bash
Running interactive command

To run bash:

docker run --privileged \
    -e RUNASUID=$(id -u) \
    --rm -ti sasol/dind4j:latest bash
Running in CI

Can be used also to get newer version of docker in CI. Common case for travis or shippable where their versions are always few releases behind the latest. shippable.yml example:

build:
  cache: true
  cache_dir_list:
    - $SHIPPABLE_BUILD_DIR/.cache
  pre_ci_boot:
    options: "-v $SHIPPABLE_BUILD_DIR:$SHIPPABLE_BUILD_DIR"
  ci:
    - >
      docker run --privileged -w /build -v ${SHIPPABLE_BUILD_DIR}:/build 
      --rm sasol/dind4j:latest
      ./gradlew --no-daemon --project-cache-dir=.cache --gradle-user-home=.cache clean test

Gitlab CI, Travis CI also works.

Internal user 'user'
  • has home folder in /home/user - you can mount stuff in there, just make sure its contents are owned by RUNASUID

Tag summary

Content type

Image

Digest

Size

244 MB

Last updated

over 8 years ago

docker pull sasol/dind4j