After docker-compose build the docker-compose up run old not updated containers

别说谁变了你拦得住时间么 提交于 2019-12-08 14:24:25

You could use, docker-compose up --build or docker-compose up --build --force-recreate

I have a helper function to nuke everything so that our Continuous blah, cycle can be tested, erm... continuously. Basically it boils down to the following:

To clear containers:

docker rm -f $(docker ps -a -q)

To clear images:

docker rmi -f $(docker images -a -q)

To clear volumes:

docker volume rm $(docker volume ls -q)

To clear networks:

docker network rm $(docker network ls | tail -n+2 | awk '{if($2 !~ /bridge|none|host/){ print $1 }}')

I generally don't require old containers, volumes and networks, so to clear them all I made a bash script which runs to clean up docker environment before each build. And to rebuild the docker using updated code, I use docker-compose up --build

Credits to marcelmfs and borrowed from Source

In this case first we should remove old containers (by rm -f). So we can deploy new code by:

docker-compose build
docker-compose stop
docker-compose rm -f
docker-compose up

Above sequence is not coincidence - when first instruction build image, the old images running - but when building is finish then old container is stopped, deleted and exchange by new builded one.

I put above commands in handy copy-paste oneliner:

docker-compose build && docker-compose stop && docker-compose rm -f && docker-compose up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!