【问题标题】:Running docker integration test containers while dev containers running在开发容器运行时运行 docker 集成测试容器
【发布时间】:2016-12-25 18:23:50
【问题描述】:

我有一个如下所示的 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-compose 看起来像这样:

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

当我尝试运行make devmake test 时,后者会使用新名称(“-test”)重新构建开发容器,而不是创建一整套单独的容器——这正是我想要的.

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

【问题讨论】:

    标签: testing docker integration-testing docker-compose


    【解决方案1】:

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

    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_PROJECT_NAME 环境变量,而不是使用-p
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    相关资源
    最近更新 更多