Docker-Compose多个本地环境

我目前正在使用docker-compose进行本地开发和本地testing环境。 后者是开发环境的克隆,具有一些不同的ENV值。 我期望能够启动一个testing环境,在后台运行我的testing,同时继续在我的开发环境中工作。 这是我目前的工作:

common.yml

 api-code: build: api volumes: - ../../:/var/www/api/ api-php: build: php ports: - "9000:9000" api-web: build: nginx ports: - "80:80" - "443:443" volumes: - ./nginx/ssl:/var/ssl api-db: build: pg ports: - "5432:5432" api-memcached: build: memcached ports: - "11211:11211" 

发展

 api: extends: file: ../../services/common.yml service: api-code php: extends: file: ../../services/common.yml service: api-php volumes_from: - api memcached: extends: file: ../../services/common.yml service: api-memcached env_file: - .env.dev artisan: build: ../../services/artisan volumes_from: - api env_file: - .env.dev composer: build: ../../services/composer volumes_from: - api links: - artisan:artisan env_file: - .env.dev nginx: extends: file: ../../services/common.yml service: api-web links: - php:php volumes_from: - api volumes: - ../../services/nginx/sites/site.conf:/etc/nginx/sites-enabled/site.conf pg: extends: file: ../../services/common.yml service: api-db env_file: - .env.dev 

testing

 api: extends: file: ../../services/common.yml service: api-code php: extends: file: ../../services/common.yml service: api-php volumes_from: - api memcached: extends: file: ../../services/common.yml service: api-memcached env_file: - .env.test codeception: build: ../../services/codeception volumes_from: - api links: - nginx:nginx env_file: - .env.test extra_hosts: - "site-test.whatever.com:xx.xx.xx.xx" artisan: build: ../../services/artisan volumes_from: - api env_file: - .env.test composer: build: ../../services/composer volumes_from: - api links: - artisan:artisan env_file: - .env.test nginx: extends: file: ../../services/common.yml service: api-web links: - php:php volumes_from: - api volumes: - ../../services/nginx/sites/site-test.conf:/etc/nginx/sites-enabled/site-test.conf pg: extends: file: ../../services/common.yml service: api-db env_file: - .env.test 

我是Docker的新手,所以我认为这可能是一个非常幼稚的方法,但现在,它正在工作。 缺点是我一次只能创build一个环境。 当我想运行testing时,我必须停止工作,直到testing结束。

我不确定如何调出testing环境而不指定volume映射到容器。 根据这些文档 ,我正在阅读它们,因为我可以运行docker-compose -f testing.yml up -d ,在我的testing.yml文件中,我不会在api容器上指定volume 。 当我这样做时,显然在容器中没有代码,所以一切都炸开了。

我怎样才能build立的容器外的不可变的代码的api容器? 我试着先build立开发,然后运行docker-compose -f testing.yml up -d ,没有运气。 我也尝试引用本地的API图像没有运气。

任何帮助是极大的赞赏。

如果您需要在图像中包含任何文件,请在Dockerfile使用ADDCOPY 。 您可以稍后为开发环境覆盖这些文件。

您还可以设置项目名称以确保环境不重叠: http : //docs.docker.com/compose/#Multiple-isolated-environments-on-a-single-host