Mehdi Haghgoo
Mehdi Haghgoo

Reputation: 3484

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?

Upvotes: 2

Views: 3609

Answers (1)

missytake
missytake

Reputation: 46

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

Upvotes: 2

Related Questions