2

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?

4

2 回答 2

4

Github for Docker compose 上有一个相关问题,您可能想查看。

于 2015-04-05T01:56:00.683 回答
2

这只是基于我最初评论的答案。

当从同一个镜像构建多个服务时,重新构建它通常是安全的。在这种情况下,bundle可以只构建.. 由于您只是web再次构建,它将被缓存(从而快速构建)并具有相同的图像 ID。

于 2015-04-06T16:24:25.707 回答