How to rebuild docker container in docker-compose.

2020-05-11 00:11发布

There are scope of services which defined in docker-compose.yml. These service have been started. I need to rebuild only one of these and start it without up other services. I run the following commands:

docker-compose up -d # run all services
docker-compose stop nginx # stop only one. but it still running !!!
docker-compose build --no-cache nginx 
docker-compose up -d --no-deps # link nginx to other services

At the end i got old nginx container. By the way docker-compose doesn't kill all running containers !

9条回答
Melony?
2楼-- · 2020-05-11 00:26

This should fix your problem:

docker-compose ps # lists all services (id, name)
docker-compose stop <id/name> #this will stop only the selected container
docker-compose rm <id/name> # this will remove the docker container permanently 
docker-compose up # builds/rebuilds all not already built container 
查看更多
手持菜刀,她持情操
3楼-- · 2020-05-11 00:29

Only:

$ docker-compose restart [yml_service_name]
查看更多
SAY GOODBYE
4楼-- · 2020-05-11 00:31

Maybe these steps are not quite correct, but I do like this:

stop docker compose: $ docker-compose down

remove the container: $ docker system prune -a

start docker compose: $ docker-compose up -d

查看更多
登录 后发表回答