[英]How to forbid recreating docker containers with docker-compose up
I need your help!我需要你的帮助!
I started using docker this week, launched all containers for a new Django project.我本周开始使用 docker,为新的 Django 项目启动了所有容器。 In this project there are several databases, python, django web server + redis, celery, etc. These all are served by separated docker containers and are launched by
docker-compose up
command. In this project there are several databases, python, django web server + redis, celery, etc. These all are served by separated docker containers and are launched by
docker-compose up
command.
This is my probjem: when I type docker-compose up
in the console, it starts all services.这是我的问题:当我在控制台中输入
docker-compose up
,它会启动所有服务。 Then I need to restore my databases dumps for each database (it takes about an hour).然后我需要为每个数据库恢复我的数据库转储(大约需要一个小时)。 But when I use pycharm tools for docker-compose, it recreates some containers.
但是当我为 docker-compose 使用 pycharm 工具时,它会重新创建一些容器。 And also it recreates all my postgres databases with ALL MY DATA!
它还使用我的所有数据重新创建了我所有的 postgres 数据库!
Sometimes is doesn't recreate containers and I can do my job, but if I do any wrong move -then docker-compose erases my databases!有时它不会重新创建容器,我可以做我的工作,但如果我做错了 - 然后 docker-compose 会删除我的数据库! I have tired to restore them!
我已经厌倦了恢复它们!
Is there way to protect containers from erasing, to forbid recreate my postgres containers?有没有办法保护容器不被擦除,禁止重新创建我的 postgres 容器?
PS: I've also tried to export postgres containers to.tar file, but when I import it back, database insight the container is ok and container importing is faster than restoring data from sql, but metadata of docker image is different, so I can't use it. PS:我也尝试将 postgres 容器导出到 .tar 文件,但是当我将其导入回来时,数据库洞察容器正常并且容器导入比从 sql 恢复数据更快,但是 docker 图像的元数据不同,所以我不能使用它。
Please, give me any ideas)请给我任何想法)
Try to use volumes to store your data.尝试使用卷来存储您的数据。 Volumes can keep data after containers recreating.
卷可以在容器重新创建后保留数据。 https://docs.docker.com/storage/volumes/
https://docs.docker.com/storage/volumes/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.