Score:0

Optimzing Docker Builds with docker-compose.yml when using PostGres DB's, performance, etc

cn flag

I just have a general about how best to build and manage DB servers when using Docker builds with docker-compose.yml. Historically, I've sometimes bound the Postgres DB's to a bound folder on the host FS. There are upsides and downsides to that it seems, but more recently it seems like it might be better to use docker volumes instead. Those are not quite as 'visible' on the host because different setups and OS's might put the docker volumes in different places, and I often develop on MacOS or Windows, but deploy on LINUX.

As an example with Postgres:

postgres:
  image: postgres:15
  ports:
    - "5557:5432"
  restart: unless-stopped
  volumes:
    - ./Postgres:/var/lib/postgresql/data vs. Postgres:/var/lib/postgresql/data
  command:  postgres -c stats_temp_directory=/tmp
  env_file:
    - ./config/.env

Where I would need the volume below if I want to use a docker volume vs. the bound host folder.

volumes:
  Postgres:

I'm just trying various configurations to optimize performance and portability, taking into account that some servers might have the system on an SSD and other mounted parts of the file system on a RAID, a NFS or in the Cloud even.

I presume that there are other settings for postgres that I should adjust for best performance. There is a related quite popular question that I asked previously here:

https://stackoverflow.com/questions/66325175/docker-container-with-postgres-warning-could-not-open-statistics-file-pg-stat

that I think could be solved by using a docker volume completely owned by docker vs. mapping to a bound folder on the host ??

Just looking for some suggestions as to how to optimize DB performance in that kind of setup. My MySQL DB's are not that large, i.e. maybe 2GB, and the postgres DB's are even smaller, although both could grow to maybe 10 GB over the next few years. I've read that running ACUUM, ANALYZE, and REINDEX in postgres can be helpful.

Also, if I wanted to migrate it seems like some options would be to copy my host folder contents to the volume using something like this:

docker run --rm \
  -v ./MySQL_DB:/from \
  -v MySQL_DB:/to \
  alpine ash -c "cd /from ; cp -av . /to"

vs. just creating a new DB on the new volumes and then importing dumped DB's into the volumes using the CLI in the Containers ?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.