# Configuring a Postgres Docker container

**URL:** <https://discuss.rubyonrails.org/t/configuring-a-postgres-docker-container/77276>\
**Category:** rubyonrails-talk\
**Created:** [February 26, 2021, 7:15am UTC](https://discuss.rubyonrails.org/t/configuring-a-postgres-docker-container/77276 "2021-02-26T07:15:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhsu802701](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jhsu802701](https://discuss.rubyonrails.org/u/jhsu802701)\
**Post date:** [February 26, 2021, 7:15am UTC](https://discuss.rubyonrails.org/t/configuring-a-postgres-docker-container/77276/1 "2021-02-26T07:15:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![evenreven](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/evenreven/32/2999_2.png) [@evenreven](https://discuss.rubyonrails.org/u/evenreven)\
**Post date:** [February 26, 2021, 11:59am UTC](https://discuss.rubyonrails.org/t/configuring-a-postgres-docker-container/77276/2 "2021-02-26T11:59:24Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![jhsu802701](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jhsu802701](https://discuss.rubyonrails.org/u/jhsu802701)\
**Post date:** [February 26, 2021, 3:07pm UTC](https://discuss.rubyonrails.org/t/configuring-a-postgres-docker-container/77276/3 "2021-02-26T15:07:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![evenreven](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/evenreven/32/2999_2.png) [@evenreven](https://discuss.rubyonrails.org/u/evenreven)\
**Post date:** [February 27, 2021, 7:12am UTC](https://discuss.rubyonrails.org/t/configuring-a-postgres-docker-container/77276/4 "2021-02-27T07:12:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jhsu802701](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@jhsu802701](https://discuss.rubyonrails.org/u/jhsu802701)\
**Post date:** [March 8, 2021, 8:50pm UTC](https://discuss.rubyonrails.org/t/configuring-a-postgres-docker-container/77276/5 "2021-03-08T20:50:07Z")

</div>

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.](https://github.com/jhsu802701/adopt-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.
