Struggling with PostgreSQL Docker Volume Mounts

0
7
Asked By TechyCat27 On

I'm setting up a Docker container for Odoo with PostgreSQL and I've specified a volume for PostgreSQL in my docker-compose.yml file to point to a mounted drive at `/mnt/postgresql`. However, even though I've configured the mounting properly, the `/mnt/postgresql` folder remains empty after I input data. I'm not sure what I'm missing here. Here's the relevant part of my configuration:

```yaml
version: '2'
services:
db:
image: postgres:17
user: root
environment:
- POSTGRES_USER=odoo
- POSTGRES_PASSWORD=odoo18@2024
- POSTGRES_DB=postgres
restart: always
volumes:
- ./postgresql:/mnt/postgresql
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
odoo18:
image: odoo:18.0-20241125
user: root
depends_on:
- db
ports:
- "10018:8069"
- "20018:8072"
tty: true
environment:
- HOST=db
- USER=odoo
- PASSWORD=odoo18@2024
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- ./addons:/mnt/extra-addons
- ./etc:/etc/odoo
restart: always
```

I made sure the folder is writable by the container, but I'm stuck. Any insights would be appreciated!

2 Answers

Answered By PostgresPro90 On

Yeah, that's definitely where the data directory should be, as per Docker Hub examples. After changing the mount point, if you restart the container, you shouldn’t lose any data, as long as you transfer your data to the new path before you restart.

OdooLover99 -

Really? Just to confirm, I won’t lose my data even if I restart the container? I've got a ton of products set up already, and I really don't want to redo everything.

Answered By DockerNinja42 On

It looks like your volume mounts might not be set correctly. You should point the mounted volume to `/var/lib/postgresql/data` in the container instead of `/mnt/postgresql`. So it should look like this: `./postgresql:/var/lib/postgresql/data`. This is where PostgreSQL stores its data by default, and that should help you see the data when you check your mounted directory.

OdooLover99 -

Got it, thanks! But now how do I move my existing data to this new path without losing it? Is there a way to do it without starting everything from scratch?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.