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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With