Docker-组合多个本地环境
Docker-Compose Multiple Local Environments
我目前正在使用 docker-compose
进行本地开发和本地测试环境。后者是开发环境的克隆,具有一些不同的 ENV
值。我希望能够启动一个测试环境,运行 我在后台进行测试,同时继续在我的开发环境中工作。这是我目前正在使用的东西:
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
测试
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 的新手,所以我认为这可能是一种非常幼稚的方法,但就目前而言,它是有效的。缺点是我一次只能带 up
一个环境。当我想 运行 测试时,我必须停止工作直到测试完成。
我不确定如何在不指定 volume
映射到容器的情况下启动测试环境。根据 these docs,我正在尽我所能阅读它们 运行 docker-compose -f testing.yml up -d
,在我的 testing.yml
文件中,我不会在 [=] 上指定 volume
21=] 容器。当我这样做时,显然容器中没有代码,所以其他一切都崩溃了。
如何使用容器外部不可变的代码构建 api
容器?我先尝试构建开发,然后 运行ning docker-compose -f testing.yml up -d
但没有成功。我也试过引用本地 api 图片,但没有成功。
非常感谢任何帮助。
如果您需要在图像中包含任何文件,请在 Dockerfile
中使用 ADD
或 COPY
。您可以稍后为开发环境使用卷覆盖这些文件。
您还可以设置项目名称以确保环境不重叠:http://docs.docker.com/compose/#Multiple-isolated-environments-on-a-single-host
我目前正在使用 docker-compose
进行本地开发和本地测试环境。后者是开发环境的克隆,具有一些不同的 ENV
值。我希望能够启动一个测试环境,运行 我在后台进行测试,同时继续在我的开发环境中工作。这是我目前正在使用的东西:
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
测试
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 的新手,所以我认为这可能是一种非常幼稚的方法,但就目前而言,它是有效的。缺点是我一次只能带 up
一个环境。当我想 运行 测试时,我必须停止工作直到测试完成。
我不确定如何在不指定 volume
映射到容器的情况下启动测试环境。根据 these docs,我正在尽我所能阅读它们 运行 docker-compose -f testing.yml up -d
,在我的 testing.yml
文件中,我不会在 [=] 上指定 volume
21=] 容器。当我这样做时,显然容器中没有代码,所以其他一切都崩溃了。
如何使用容器外部不可变的代码构建 api
容器?我先尝试构建开发,然后 运行ning docker-compose -f testing.yml up -d
但没有成功。我也试过引用本地 api 图片,但没有成功。
非常感谢任何帮助。
如果您需要在图像中包含任何文件,请在 Dockerfile
中使用 ADD
或 COPY
。您可以稍后为开发环境使用卷覆盖这些文件。
您还可以设置项目名称以确保环境不重叠:http://docs.docker.com/compose/#Multiple-isolated-environments-on-a-single-host