How to set/get the project name in docker-compose.yml
Answer a question
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?
Answers
This is just an answer based on my initial comment.
When building multiple services off of the same image it is usually safe to just build it again. In this case, bundle can just build .. Since you are just building web again, it will be cached (thus building quickly) and have the same image ID as well.
更多推荐
所有评论(0)