我測(cè)試的是保留的,比如我在mysql鏡像數(shù)據(jù)庫(kù)里新建了一個(gè)表,
重新docker-compose up
以后,之前的表還存在,
不過(guò)沒(méi)法理解啊,難道docker-compose up
不是重新生成了鏡像的實(shí)例嗎?
每個(gè)docker-compose.yml其實(shí)只能生成一個(gè)實(shí)例?要reset的話(huà)必須手動(dòng)刪除之前的實(shí)例
docker-compose up
Priority will be given to using existing containers instead of creating new ones.
The following method can solve your problem:
docker-compose up -d --force-recreate
使用 --force-recreate
You can force the container to be rebuilt (otherwise the container will only be rebuilt when the container configuration changes)
docker-compose down
Stop all containers and delete the container (so it will be a new container the next time you use docker-compose down
停止所有容器,并刪除容器 (這樣下次使用docker-compose up
)
docker-compose up is to create and start a container. As far as I know, there are only three situations where the container will be re-created (that is, the old container will be deleted first, and then a new one will be generated):
1. When the image is updated, the container will be re-created. Re-create the container;
2. The container does not exist (that is, it has been deleted);
3. When container A is re-created, the containers that depend on this container will be re-created (that is, the container in the docker-compose.yml file is set depends_on is the container of container A)