Docker mysql image - move internal container DB to the volume

Viewed 2219

I have started using docker with docker-compose where I have the database defined. Since I did not have volumes defined in the configuration (my mistake), the database has been created inside the container and now next time when I run docker-pull, I will get this database re-created causing my data loss. What would be the best way to move the data out of the container without losing the data?

  db:
    image: "mydbimage"
    environment:
      MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
      MYSQL_DATABASE: "jirio"
      MYSQL_USER: "${DB_USERNAME}"
      MYSQL_PASSWORD: "${DB_PASSWORD}"

Dockerfile

FROM mysql:5.6
ADD schema.sql /docker-entrypoint-initdb.d/schema.sql
2 Answers
Related