简体   繁体   中英

Docker-Compose: Bash command substitution

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM