How to get docker-compose to always re-create containers from fresh images?

后端 未结 7 2107
误落风尘
误落风尘 2020-11-29 15:13

My docker images are built on a Jenkins CI server and are pushed to our private Docker Registry. My goal is to provision environments with docker-compose which always start

7条回答
  •  粉色の甜心
    2020-11-29 15:35

    docker-compose up --force-recreate is one option, but if you're using it for CI, I would start the build with docker-compose rm -f to stop and remove the containers and volumes (then follow it with pull and up).

    This is what I use:

    docker-compose rm -f
    docker-compose pull
    docker-compose up --build -d
    # Run some tests
    ./tests
    docker-compose stop -t 1
    

    The reason containers are recreated is to preserve any data volumes that might be used (and it also happens to make up a lot faster).

    If you're doing CI you don't want that, so just removing everything should get you want you want.

    Update: use up --build which was added in docker-compose 1.7

提交回复
热议问题