Testing 在开发容器运行时运行docker集成测试容器

Testing 在开发容器运行时运行docker集成测试容器,testing,docker,integration-testing,docker-compose,Testing,Docker,Integration Testing,Docker Compose,我有一个Makefile,如下所示: dev: docker-compose up -d --build test: DOCKER_ENV="-test" docker-compose up -d --build // run some integration tests on the containers then // shut them down (and let ephemeral database disappear) DOCKER_ENV="

我有一个Makefile,如下所示:

dev:
    docker-compose up -d --build

test:
    DOCKER_ENV="-test" docker-compose up -d --build
    // run some integration tests on the containers then
    // shut them down (and let ephemeral database disappear)
    DOCKER_ENV="-test" docker-compose down -v
services:
  foo:
    container_name: foo${DOCKER_ENV}
    image: foo:latest
  bar:
    container_name: bar${DOCKER_ENV}
    image: bar:latest
我的docker compose如下所示:

dev:
    docker-compose up -d --build

test:
    DOCKER_ENV="-test" docker-compose up -d --build
    // run some integration tests on the containers then
    // shut them down (and let ephemeral database disappear)
    DOCKER_ENV="-test" docker-compose down -v
services:
  foo:
    container_name: foo${DOCKER_ENV}
    image: foo:latest
  bar:
    container_name: bar${DOCKER_ENV}
    image: bar:latest
当我尝试运行
makedev
然后运行
maketest
时,后者会使用新名称(“-test”)重新生成dev容器,而不是创建一整套独立的容器,这正是我想要的


如何保持开发环境运行并定期启动测试环境?(我们将在某个时候在CI上执行此操作,但我希望开发人员能够在本地运行所有测试。)

使用docker compose项目名称将开发人员与测试分开,例如:

dev:
    docker-compose up -d --build

test:
    export DOCKER_PROJ=`basename \`pwd\``"-test"
    docker-compose -p ${DOCKER_PROJ} up -d --build
    // run some integration tests on the containers then
    // shut them down (and let ephemeral database disappear)
    docker-compose -p ${DOCKER_PROJ} down -v

(我的Makefile语法有点生疏,我相信有更干净的方法可以做到这一点。)

您还可以设置
COMPOSE\u PROJECT\u NAME
env变量,而不是使用
-p