Docker Community Forums

Share and learn in the Docker community.

How to pass docker volume name to docker compose.yml

I know needed volume name

sudo docker volume ls

And I want to pass this volume (but with opportunity to changing it in command line) to docker compose file.

  image: "nginx:alpine"
    - 6000:80
    - registry:registry
    - ./auth:/etc/nginx/conf.d
    - ./auth/nginx.conf:/etc/nginx/nginx.conf:ro
    - ./auth/domain.crt:/etc/ssl/certs/nginx-selfsigned.crt:ro
    - ./auth/domain.key:/etc/ssl/private/nginx-selfsigned.key:ro

  image: 5money:latest
    - registry-external-data:/var/lib/registry

    external: true
    ??name: $data??

I don’t understand last line in composer file, what is correct? I want start compose something like this:

sudo docker-compose -f 5money-compose.yml up -d -e data=cfc151dc475be39535b438d54d245107c5f1ce022622a0eae53bc03016aa987d
  • docker-compose up does not have -e to set environment variables
  • docker-compose run has but those variables will be available by a process in the running container not by the yaml parser
  • You can use variables in the docker-compoye.yml if you create a file named .env next to the docker-compose.yml to set the variable like:

You could also “rename” the volume. I mean copy and delete the original. I created some scripts for Docker years ago. I tried docker-volume-copy now and still works. GitHub - itsziget/scripts-for-docker: Useful scripts you can use with Docker to save some time

docker-volume-copy cfc151dc475be39535b438d54d245107c5f1ce022622a0eae53bc03016aa987d registry-external-data

Then you could know what that volume is when you run docker volume ls. Obviously you would have to change the value of the variable.

Cool, this is great scripts. And thank you, I’m understand about -e parameters to composer. But I’m still confused - what correct last line in compose file? I’m not sure about “name” - is this correct?

The last line is correct except those question marks, but I am sure those are not in the original compose file.

Don’t use links, they have been deprecated

1 Like