两个不同的泊坞窗图片,一个用于开发,另一个用于测试。以及使用这些图像的两个不同的docker-compose文件
泊坞窗图片
lukas@E7450:~$ docker images
cbs/compare-dev webapp 79ace960ede7 About an hour ago 852.8 MB
cbs/compare-test webapp 10da03e3922b About an hour ago 846.2 MB
作曲家-development.yml
version: '2'
services:
redis:
restart: always
image: redis
container_name: compare_dev_redis
links:
- webapp
volumes:
- /home/data/compare/development/database/redis:/data
volumes_from:
- webapp
command: redis-server /srv/www/compare/htdocs/config/services/compare.redis.conf
varnish:
restart: always
image: ldynia/varnish
container_name: compare_dev_varnish
links:
- webapp
volumes:
- ./scripts/startup_varnish.sh:/etc/varnish/startup_varnish.sh
volumes_from:
- webapp
environment:
CACHE_SIZE: 256m
VCL_PORT: 8080
VCL_CONFIG: /srv/www/compare/htdocs/config/services/compare.varnish.development.vcl
command: bash startup_varnish.sh
database:
restart: always
image: postgres:9.5.3
container_name: compare_dev_postgres
environment:
ENVIRONMENT: developement
POSTGRES_DB: compare_development
POSTGRES_USER: developer
POSTGRES_PASSWORD: developer
volumes:
- /home/data/compare/development/database/postgres:/var/lib/postgresql/data
webapp:
restart: always
depends_on:
- database
image: cbs/compare-dev:webapp
container_name: compare_dev_webapp
build: docker/development
ports:
- "22:22"
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- .:/srv/www/compare/htdocs
- ./storage:/srv/www/compare/htdocs/storage
environment:
HTTP_PORT: 80
HOST: compare.dev
command: bash scripts/startup_app.sh
作曲家-testing.yml
version: '2'
services:
redis:
image: redis
container_name: compare_test_redis
links:
- webapp
volumes:
- /home/data/compare/testing/database/redis:/data
volumes_from:
- webapp
command: redis-server /srv/www/compare/htdocs/config/services/compare.redis.conf
varnish:
image: ldynia/varnish
container_name: compare_test_varnish
links:
- webapp
volumes:
- ./scripts/startup_varnish.sh:/etc/varnish/startup_varnish.sh
volumes_from:
- webapp
environment:
CACHE_SIZE: 256m
VCL_PORT: 9090
VCL_CONFIG: /srv/www/compare/htdocs/config/services/compare.varnish.production.vcl
command: bash startup_varnish.sh
database:
image: postgres:9.5.3
container_name: compare_test_postgres
environment:
ENVIRONMENT: production
POSTGRES_DB: compare_testing
#POSTGRES_USER: !!! CHANGE ME !!!
#POSTGRES_PASSWORD: !!! CHANGE ME !!!
volumes:
- /home/data/compare/testing/database/postgres:/var/lib/postgresql/data
webapp:
depends_on:
- database
image: cbs/compare-test:webapp
container_name: compare_test_webapp
build: docker/testing
ports:
- "555:443"
- "9000:80"
volumes:
- .:/srv/www/compare/htdocs
- ./storage:/srv/www/compare/htdocs/storage
- /etc/ssl/private/servercerts:/etc/ssl/private/servercerts
environment:
HTTP_PORT: 555
HOST: compare.cbs.dtu.dk
command: bash scripts/startup_app.sh
当我使用单个撰写文件时,一切正常。
仅运行开发容器。
lukas@E7450:~$ docker-compose -f composer-development.yml up -d
lukas@E7450:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cb3840ae6e8d ldynia/varnish "bash startup_varnish" 40 seconds ago Up 40 seconds compare_dev_varnish
980a90cf8177 redis "docker-entrypoint.sh" 42 seconds ago Up 42 seconds 6379/tcp compare_dev_redis
8c4ed8c08705 cbs/compare-dev:webapp "bash scripts/startup" 45 seconds ago Up 44 seconds 0.0.0.0:22->22/tcp, 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:8080->8080/tcp compare_dev_webapp
9e7fca1a63ce postgres:9.5.3 "/docker-entrypoint.s" 11 seconds ago Up 11 seconds 5432/tcp compare_dev_postgres
仅运行测试容器。
lukas@E7450:~$ docker-compose -f composer-testing.yml up -d
lukas@E7450:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8df766e350d4 redis "docker-entrypoint.sh" 11 seconds ago Up 9 seconds 6379/tcp compare_test_redis
0174348650e7 ldynia/varnish "bash startup_varnish" 11 seconds ago Up 10 seconds compare_test_varnish
17c6838d378c cbs/compare-test:webapp "bash scripts/startup" 11 seconds ago Up 10 seconds 0.0.0.0:9000->80/tcp, 0.0.0.0:555->443/tcp compare_test_webapp
9f78d61a19f8 postgres:9.5.3 "/docker-entrypoint.s" 11 seconds ago Up 11 seconds 5432/tcp compare_test_postgres
当我尝试同时运行两个容器时出现问题。也就是说,开发容器已经由 docker-compose -f composer-development.yml up -d 触发。现在我开始测试容器 docker-compose -f composer-testing.yml up -d ,这就是发生的事情。
lukas@E7450: docker-compose -f composer-testing.yml up
Recreating compare_dev_postgres
Recreating compare_dev_webapp
Recreating compare_dev_redis
Recreating compare_dev_varnish
Attaching to compare_test_postgres, compare_test_webapp, compare_test_varnish, compare_test_redis
以某种方式,docker-compose决定重新创建并停止 developpement 容器 - 仅使用测试容器离开我。我所期望的是,有两个容器同时运行(开发和测试容器)我只有测试容器!
ludd@E7450:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f66b54032ca2 ldynia/varnish "bash startup_varnish" 8 minutes ago Up 2 minutes compare_test_varnish
83626ac27c32 redis "docker-entrypoint.sh" 8 minutes ago Up 2 minutes 6379/tcp compare_test_redis
97ad2f330272 cbs/compare-test:webapp "bash scripts/startup" 8 minutes ago Up 2 minutes 0.0.0.0:9000->80/tcp, 0.0.0.0:555->443/tcp compare_test_webapp
4f174819744d postgres:9.5.3 "/docker-entrypoint.s" 8 minutes ago Up 2 minutes 5432/tcp compare_test_postgres
为什么我不能同时运行这两个容器?为什么启动测试容器会停止开发容器?如何并行运行这两个容器?</ p>
答案 0 :(得分:8)
您可以将此视为同一项目,因为您从同一目录运行并且没有定义项目。因此,它使当前项目看起来像你最后给出的撰写文件。
要同时运行它们,请运行它们:
docker-compose -f composer-development.yml -p dev up -d
docker-compose -f composer-testing.yml -p test up -d