Mariadb tables are deleted when use volume in docker-compose

  docker, mariadb, mysql

I’m copy previous mariadb container’s data(/var/lib/mysql) and paste data to new container image.
this is Dockerfile

FROM mariadb:latest

ENV MYSQL_ROOT_PASSWORD tt
ENV MYSQL_DATABASE tt
ENV MYSQL_USER tt
ENV MYSQL_PASSWORD tt

# copy other database data
ADD mysql /var/lib/mysql
RUN chown -R mysql:mysql /var/lib/mysql

VOLUME /var/lib/mysql

EXPOSE 3306

CMD ["mysqld"]

when I build docker image, all table remained

but run docker image by using volume, all table disappear, just db.opt remains.

how can i get database’s data with using volume?

Source: Docker Questions

LEAVE A COMMENT