6

I have a docker-compose.yml which contains the stuff to start a jenkins-server on CentOS7:

jenkins:
  image: jenkins
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - $(which docker):/usr/bin/docker:ro
    - /usr/lib64/libsystemd-journal.so.0:/usr/lib/x86_64-linux-gnu/libsystemd-journal.so.0
    - /usr/lib64/libsystemd-id128.so.0:/usr/lib/x86_64-linux-gnu/libsystemd-id128.so.0
    - /usr/lib64/libdevmapper.so.1.02:/usr/lib/x86_64-linux-gnu/libdevmapper.so.1.02
    - /usr/lib64/libgcrypt.so.11:/usr/lib/x86_64-linux-gnu/libgcrypt.so.11
    - /usr/lib64/libdw.so.1:/usr/lib/x86_64-linux-gnu/libdw.so.1
  ports:
    - "8080:8080"

But I'm not able to run the compose because I keep getting an error on $(which docker):/usr/bin/docker:ro. How do I have to fix this?

Error: ERROR: Invalid interpolation format for "volumes" option in service "jenkins": "$(which docker):/usr/bin/docker:ro"

Is it still not possible to include environment variables? I'm searching for the most right solution. Thanks

lvthillo
  • 28,263
  • 13
  • 94
  • 127
  • 1
    Possible duplicate of [How can I escape a $ dollar sign in a docker compose file?](https://stackoverflow.com/questions/40619582/how-can-i-escape-a-dollar-sign-in-a-docker-compose-file) – kenorb Feb 16 '19 at 13:47

1 Answers1

7

$(...) is not an environment variable, it's command substituion.

You need to use an environment variable to pass in the value.

DOCKER_PATH=$(which docker) docker-compose up

docker-compose.yaml (snippet)

- ${DOCKER_PATH}:/usr/bin/docker:ro
dnephin
  • 25,944
  • 9
  • 55
  • 45
  • 3
    Alternatively, you can escape the $ sign with $$, see here: https://docs.docker.com/compose/compose-file/#variable-substitution – batjko Mar 07 '17 at 14:51