运行docker集成testing容器,同时运行dev容器

我有一个看起来像这样的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 

我的docker写作看起来像这样:

 services: foo: container_name: foo${DOCKER_ENV} image: foo:latest bar: container_name: bar${DOCKER_ENV} image: bar:latest 

当我尝试运行make dev然后make test ,后者会导致用新名称(“-test”)重builddev容器,而不是创build一整套单独的容器,这正是我想要的。

我怎样才能保持开发环境的运行,并定期启动testing环境? (我们会在CI上这样做,但是我希望开发者能够在本地运行所有的testing。)

使用docker-compose项目名称将dev与testing分开,例如:

 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语法有点生疏,我敢肯定有更干净的方法来做到这一点。)