Dogfooding it, Pt 5 - PostgreSQL

Since I'll now be using configuration files rather heavily, it's probably a good idea to make those available for download. And, in the spirit of self-hosting things, why put them on GitHub when I can host Gitea and show off another service?

Now, I know Gitea could use MySQL as database backend, but I would personally prefer to limit use of that as much as possible. Postgres is my prerred DB engine, and now I have an excuse to deploy it.

So, append to our docker-compose:

  postgres:
    deploy:
      replicas: 1
    environment:
      POSTGRES_PASSWORD_FILE: "/run/secrets/postgres-root"
    image: "postgres/postgres:16"
    logging:
      driver: journald
    networks:
      - homelab
    restart: on-failure
    secrets:
      - postgres-root
    shm_size: 128mb
    user: "10003:10003"
    volumes:
      - "/srv/data/docker/postgres/data:/var/lib/postgresq;:rw"
      - type: tmpfs
        target: /var/run/postgresql

v

Add the following to the secrets section at the head of the file:

  postgres-root:
    file: /home/<your user>/secrets/postgres-root

And generate the secrets file and the storage location for the postgres database::

 $ pwgen > ~/secrets/postgres-root
 $ mkdir -p /srv/data/docker/postgres/data
 $ chown -R 10003:10003 /srv/data/docker/postgres
 $ chmod -R g-rwx,o-rwx /srv/data/docker/postgres

And bring the stack up.

$ docker stack deploy -c <compose-file> --prune homelab

Subscribe to Homelab Adventures

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe