Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating A Docker Volume to Podman

I used to have a Docker volume for mariadb, which contained my database. As part of migration from Docker to Podman, I am trying to migrate the db volume as well. The way I tried this is as follows:

1- Copy the content of the named docker volume (/var/lib/docker/volumes/mydb_vol) to a new directory I want to use for Podman volumes (/opt/volumes/mydb_vol) 2- Run Podman run:

podman run --name mariadb-service -v /opt/volumes/mydb_vol:/var/lib/mysql/data:Z -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=mysecret -e MYSQL_DATABASE=wordpress --net host mariadb

This successfully creates a container and initializes the database with the given environment variables. The problem is that the database in the container is empty! I tried changing host mounted volume to /opt/volumes/mydb_vol/_data and container volume to /var/lib/mysql simultaneously and one at a time. None of them worked.

As a matter of fact, when I "podman execute -ti container_digest bash" inside the resulting container, I can see that the tables have been mounted successfully in the specified container directories, but mysql shell says the database is empty!

Any idea how to properly migrate Docker volumes to Podman? Is this even possible?

like image 437
djnotes Avatar asked Dec 01 '25 03:12

djnotes


1 Answers

I solved it by not treating the directory as a docker volume, but instead mounting it into the container:

podman run \
 --name mariadb-service \
 --mount type=bind,source=/opt/volumes/mydb_vol/data,destination=/var/lib/mysql \
 -e MYSQL_USER=wordpress \
 -e MYSQL_PASSWORD=mysecret \
 -e MYSQL_DATABASE=wordpress \
 mariadb
like image 125
missytake Avatar answered Dec 05 '25 15:12

missytake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!