I'm trying to get an example app from https://trpc.io/docs/example-apps to work. The catch is that I wanted to run the database in docker because I use a Windows Subsystem for Linux (WSL2) Ubuntu environment. It's using postgres. This is a fairly new machine and I know I have done this in the past in pure linux.
I had hoped to use as it looked good at a quick glance: https://github.com/felipewom/docker-compose-postgres.git
My full code is here: https://github.com/ScorpIan555/simple-trpc-w-app-router there are some slight modifications, but I was able to replicate this exact same error in both Felipe's example repo, as well as my own.
.env
DATABASE_URL=postgresql://postgres:password@localhost:5432/postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_DB=postgres
PGADMIN_DEFAULT_EMAIL=[xxx]@gmail.com
PGADMIN_DEFAULT_PASSWORD=password
Error message:
2023-12-30 07:30:49 [2023-12-30 12:30:49 +0000] [93] [INFO] Booting worker with pid: 93
2023-12-30 07:30:51 [2023-12-30 12:30:51 +0000] [93] [INFO] Worker exiting (pid: 93)
2023-12-30 07:30:51 ERROR : Failed to create the directory /var/lib/pgadmin/sessions:
2023-12-30 07:30:51 [Errno 13] Permission denied: '/var/lib/pgadmin/sessions'
2023-12-30 07:30:51 HINT : Create the directory /var/lib/pgadmin/sessions, ensure it is writeable by
2023-12-30 07:30:51 'pgadmin', and try again, or, create a config_local.py file
2023-12-30 07:30:51 and override the SESSION_DB_PATH setting per
2023-12-30 07:30:51 https://www.pgadmin.org/docs/pgadmin4/8.1/config_py.html
2023-12-30 07:30:51 [2023-12-30 12:30:51 +0000] [94] [INFO] Booting worker with pid: 94
I understand that the /var/lib/ dir is owned by root. I don't know much about pgadmin, but it looks like the postgres db protocol (?) might be trying to set up a session in the container once it's running, which would be expected behavior.
Given that container file systems should be read only, I was trying to follow the error message and create the config_local.py
file, but had a permissions error when I set up a Dockerfile and did RUN touch config_local.py
. Maybe there's something dumb I'm just forgetting?
I think there are several problems with the docker-compose-postgres
repository that make it not a great example, starting with the fact that it us using bind mounts for storage rather than named volumes. Just briefly noting all of the issues:
By using bind mounts rather than named volumes, access is controlled by the ownership and permissions of your local directories. This will often lead to conflicts, and there's no good reason for it in this case (because there's no compelling reason that you need direct access to either the postgres or pgadmin backend storage).
I strongly suspect your permission issues are due to the use of bind mounts, and I think that replacing those with named volumes will solve your problem. I don't have access to a WSL environment in which to test this theory.
You don't need to explicitly create a network to be shared by the services in your compose file; docker compose
does that for you by default.
I don't think this is a good example of using the env-file
option. Since the file itself simply references other environment variables, it's nothing but another point of indirection. We can use compose's default support of a .env
to better effect.
I would probably rewrite the file to look something like this:
services:
database:
image: 'docker.io/postgres:latest'
environment:
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
ports:
- 15432:5432
volumes:
- pg-data:/var/lib/postgresql/data/
pgadmin:
image: 'docker.io/dpage/pgadmin4:latest'
environment:
PGADMIN_DEFAULT_EMAIL: "${PGADMIN_DEFAULT_EMAIL}"
PGADMIN_DEFAULT_PASSWORD: "${PGADMIN_DEFAULT_PASSWORD}"
ports:
- 15080:80
volumes:
- pgadmin-data:/var/lib/pgadmin/
volumes:
pg-data:
pgadmin-data:
If you create a .env
that looks like:
POSTGRES_PASSWORD=secret
[email protected]
PGADMIN_DEFAULT_PASSWORD=secret
And bring things up like this:
docker compose up
Then docker will automatically apply the variables in your .env
file.