简体   繁体   English

尽管使用了卷,Docker mysql 容器不会保留数据。 为什么?

[英]Docker mysql container doesn't persist data despite using volumes. Why?

I am running two docker containers.我正在运行两个 docker 容器。

  • mysql mysql
  • adminer管理员

I want to persist my database, therefore I use volumes in my docker-compose file.我想保留我的数据库,因此我在 docker-compose 文件中使用 Still I lose data whenever I restart the containers (docker-compose down and up).每当我重新启动容器(docker-compose down and up)时,我仍然会丢失数据。

What I am missing?我错过了什么? (I am on ubuntu 20.04) (我在 ubuntu 20.04)

services:
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
  db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'example' # TODO: Change this      
    volumes:
      - "./config/my.conf:/etc/mysql/conf.d/config-file.cnf"
      - "./data:/var/lib/mysql:rw"
      

Use docker-compose stop instead of docker-compose down .使用docker-compose stop代替docker-compose down

From the documentation :文档中:

docker-compose down: Stops containers and removes containers, networks, volumes , and images created by up. docker-compose down:停止容器并移除由 up 创建的容器、网络、和镜像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM