3

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?

Pang
  • 9,564
  • 146
  • 81
  • 122
aherve
  • 3,795
  • 6
  • 28
  • 41
  • Is this only for referencing the existing image? Any reason why you can't just have `bundle` build `.` again? One of the services (`bundle` or `web`) will be built first. But the second build should be near-instant since it will be cached. The image ID should be the same for both at the point as well. – Andy Shinn Apr 03 '15 at 15:56
  • You're right, that's actually all I need. You can write this as an answer if you care, or I'll do it myself. Thanks ! – aherve Apr 05 '15 at 15:14

2 Answers2

4

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

Evgeny Chernyavskiy
  • 2,584
  • 18
  • 13
2

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.

Andy Shinn
  • 26,561
  • 8
  • 75
  • 93