I am attempting to install the dockerized version of mastodon and although I've referred to several guides (including official documentation), I'm consistently getting an error connecting to the postgres database.
Here the relevant section of my docker-compose.yml:
db:
restart: always
image: postgres:9.6-alpine
shm_size: 256mb
networks:
- internal_network
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
volumes:
- ./postgres:/var/lib/postgresql/data
... and my .env.production:
# PostgreSQL
# ----------
DB_HOST=/var/run/postgresql
DB_USER=mastodon
DB_NAME=mastodon_production
DB_PASS=[MY PASSWORD] <--- (I've also tried leaving this blank with no difference in the result)
DB_PORT=5432
But when I run (for example):
$ docker-compose run --rm web rails db:migrate
I get the following output:
rails aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
and $ docker logs mastodon_db_1
gives me:
Error: Database is uninitialized and superuser password is not specified.
You must specify POSTGRES_PASSWORD to a non-empty value for the
superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".
You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
connections without a password. This is *not* recommended.
See PostgreSQL documentation about "trust":
https://www.postgresql.org/docs/current/auth-trust.html
I'm relatively new to docker but (I think) I understand the basic concepts. However, a lot of Googling has me thinking that I'm the only one who's having this issue and I can't see what I'm missing.