Using volumes to mount persistent volumes to Postgres running in a container

Created a volum:

docker volume create --opt device=/dev/sdb1 pgdata

using the following to start/run the container:

podman run --replace -d --name my-postgresdb-container -p 5432:5432 -e POSTGRES_PASSWORD=XXXXX --mount type=volume,source=pgdata,destination=/home/postgres/pgdata/data localhost/my-postgres-db:latest

container doesn’t start and we get the error:

Error: mounting volume pgdata for container 0463b76c9132e230bf6b7a90c8d99bdbeab9f323c83821b9232201e5ece5cc14: mount: /home/postgres/.local/share/containers/storage/volumes/pgdata/_data: permission denied.

any insight? w’re using Linux type file system mkfs ext2

when I remove the --mount, the container starts. not sure what is up. any help is appreciated! Thanks

Looks like the volume misses the option to declare the type. You can try if adding --opt type=ext2 helps.

Why would anyone want to use ext2 over ext4?

Update: the logs indicate a permission issue. You might need to fix the owner and/or permissions of the root of the filesystem.

I said ext4, the SA said “let’s try ext2 and see what happens”. We’ll try ext4 next, then xfs if that doesn’t work.

Thanks for the tip!

ext2 was release 32 years ago. ext4 17 years ago. I hope his/her argument was not that it’s too cutting edge :slight_smile:

You’re a funny guy :rofl::rofl::rofl:

We were running Solaris until 2019 on Sun E15Ks. The only reason we got off them was because we didn’t have the footprint and the environmentals in our new data center. We’re trying to be a little more in the present :rofl::rofl::rofl:

I originally built the persistent file systems as lvm and the SA said they should be ‘regular’ Linux file systems.

1 Like

Does this work together?

Well spotted! I missed it.

I tried to not be so fancy and just ran:

docker volume create pgdata

I mounted this using -v pgdata:/home/postgres/pgdata

I was then able to persist data between container runs.

Thanks to all that responded!

And i missed this, too.

podman=docker and docker=podman

No. It’s similar software, but it’s not 100% compatible. I would not expect a Docker volume to work with a podman container.

Most likely true. I’m a DBA and just getting started in the world of containers.
I’m just lucky, I guess. In this case a docker volume worked with a podman container.