5

I'm writing docker-compose.yml file for application that should have access to Docker from within container (Docker in Docker) according to blog post here: https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/

The problem is I need to attach host Docker binaries, but I don't know exact path of docker on target system, on some it could be /bin/docker, on others - /usr/local/bin/docker, etc.

I want to have cross-platform solution, just putting something like this

volumes:
  - $(which docker):/bin/docker

into docker-compose.yml.

Is it possible with Docker-Compose?

3
  • 2
    Why don't you just include the Docker binaries in your image? Commented Dec 22, 2015 at 10:15
  • Oliver, for this particular case it helps, but what about generic case? E.g. what if I want to map not a docker and not binaries, but some folder which can be different on different hosts? Commented Dec 22, 2015 at 10:25
  • 1
    docs.docker.com/compose/compose-file/#variable-substitution Commented Dec 22, 2015 at 10:29

1 Answer 1

5

It's actually a bad idea to to mount the Docker binary, as newer versions have dynamic binaries, so you will also need to discover and mount all the required libraries.

Instead, as Oliver suggests, it's much easier to install Docker directly inside the container and point this at the socket on the host. Note that you may have issues if you have divergent versions of Docker on the host and in the container.

To answer the question however, you can use shell environment variables in newer versions of Compose. In your Dockerfile you can do something like:

volumes:
  - ${DOCKER_PATH}:/bin/docker

And when you call compose:

DOCKER_PATH="$(which docker)" && docker-compose up

Full docs are here https://docs.docker.com/compose/compose-file/#variable-substitution

Sign up to request clarification or add additional context in comments.

1 Comment

@luckydonald true. I've added an answer. I haven't tested the code, so it might need some fixes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.