Configuring a Postgres Docker container

I’m trying to Dockerize an app. I need to change the pg_hba.conf file to change certain settings to “trust”. (The config/database.yml file does NOT specify a password in the development or test setups.)

How do I go about doing this under a Dockerized setup involving a Dockerfile and docker-compose.yml file? It would help if you can point me to an example of a Rails project on GitHub/BitBucket/Gitlab that does this.

Are you going to containerize the whole app or just Postgres? I’m asking because I’m doing local Rails development (I’m basically kinda containerizing gems and whatnot with rbenv already, so I don’t see any need to containerize the whole app), but I still containerize Postgres in development environments to avoid having running services on my main laptop. Because of this, I’m not using docker-compose or even a Dockerfile, only this: podman run --name app_db -p 5432:5432 -d -e POSTGRES_PASSWORD=password docker.io/postgres:12-alpine (I’m using podman instead of Docker, but it shouldn’t matter in this case). To make the container accept bin/rails db:create and such without hassle, I add a postgres role podman exec -it app_db bash -lc 'su - postgres -c "createuser --superuser YOURLOCALUSERNAME"'. With Docker, maybe this user should be called “root” since it’s running as superuser.

If you’re going to dockerize the entire Rails app, then that’s a different ballgame. :slight_smile:

Yes, I’m aiming to Dockerize the entire Rails app so that there is ZERO need to have Ruby, Rails, or PostgreSQL on the host OS.

That’s a very broad question. I don’t mean to be rude, but I suggest Google it, then come back with specifics. Also, you should edit the thread title since it looks like you’re only containerizing Postgres.

Thanks for your responses.

I was able to figure it out. You can see what I did in the dockerize branch at GitHub - jhsu802701/adopt-a-tree: Beautify your street by watering a tree. . The critical thing that was missing was the “host: database” line in config/database.yml .

How I figured it out was by trying things out under my preferred way (which involves specifying a password in config/database.yml) and then reconciling things to preserve the config/database.yml setup of the legacy app.