Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set/get the project name in docker-compose.yml

I'm trying to either set a docker-compose project name, or to be able to reference it within my config file. Is any of these possible?

The reason I'm asking is that I'm following this tutorial so I ended up with a docker-container.yml file that reads

web:
  build: .
  command: bundle exec rails s -p 3000 -b 0.0.0.0
  ports:
    - "3000:3000"
  links:
    - db
  volumes: 
    - ".:/myapp"
  volumes_from:
    - bundle

db:
  image: mongo
  ports:
    - "27017"

bundle:
  image: myapp_web  # <--- this is actually {$project_name}_web being hard-coded
  command: echo Hello
  volumes:
    - /bundle

Due to the image: myapp_web config, this will only work if the project name itself is myapp. This will be true if I'm working on a directory named myapp or if I use docker-compose -p myapp.

But as soon as someone changes the directory name, this will crash. I'd like to tell docker-compose to use a custom COMPOSE_PROJECT_NAME variable without having to pass the -p fancyname option.

Another way I could imagine would be to pass some kind of image: {$COMPOSE_PROJECT_NAME}_web in the yml file, but I'm really not sure this can be achieved.

Any idea?

like image 382
aherve Avatar asked Nov 14 '25 13:11

aherve


1 Answers

There's a relevant issue on Github for Docker compose that you might want to check out.

like image 163
Evgeny Chernyavskiy Avatar answered Nov 17 '25 08:11

Evgeny Chernyavskiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!