> ## Content Index
> Fetch the complete content index at: https://www.mrstebo.co.uk/llms.txt
> Use this file to discover other available public pages before exploring further.

# Ruby on Rails with Postgresql using Docker Compose
- URL: https://www.mrstebo.co.uk/ruby-on-rails-with-postgresql-using-docker-compose/
- Published: 2016-12-12T00:00:00.000Z
- Updated: 2023-05-15T23:43:46.000Z
- Author: Steven Atkinson
- Tags: Software Development, Software Engineering, Docker, Ruby On Rails, Docker Compose

So in the previous post I explained how to get a rails application up and running using Docker. But that project was using SQLite as it’s database.

What if we want to use something else?

In the Dockerfile we had installed the packages to enable us to switch our database to use ****Postgres**. So lets give it a go!

# Lets update our Gemfile

So we should probably swap the ****sqlite3** gem for ****pg** so we can load the postgres database adapter.

![](https://miro.medium.com/v2/resize:fit:300/0*pjV78P1hGDh8CPFs.png)

# And now for our database config

Lets replace all the SQLite stuff in our ****database.yml** file with our postgres settings.

# Now lets set up our Docker Compose configuration

Here is how our ****docker-compose.yml** should look:

# Lets get ready to build!

Now we can run `docker-compose build`. This will build our containers.  
Next we run `docker-compose up` to start them.

![](https://miro.medium.com/v2/resize:fit:140/0*dPG-BBJODaBuVqrp.png)

****We are not finished yet though, because if we try and navigate to our rails app we get the following error**

![](https://miro.medium.com/v2/resize:fit:300/0*R6PAgT7DjSYDAPEy.png)

This is when we need to run some commands on our running container. This is one of the reasons I use [****Cmder**](http://cmder.net/?ref=mrstebo.co.uk). I’ll just create a split terminal!

![](https://miro.medium.com/v2/resize:fit:300/0*eJzHqoG2zn_1yVE8.png)

Then we need to run the following commands in order to set up postgres for our rails app:

`docker exec -t myawesomeapp_web_1 rails db:setup`  
`docker exec -t myawesomeapp_web_1 rails db:migrate`

You will need to ****restart** docker-compose, otherwise rails will not render anything. When you stop docker-compose using ****Ctrl+C**, you will also need to delete ****tmp\\pids\\server.pid**, otherwise the `rails server` command will fail with a message saying that a server is already running.

When you run `docker-compose up` again, you should see the following page when you navigate to [****http://localhost:3000**](http://localhost:3000/?ref=mrstebo.co.uk)

![](https://miro.medium.com/v2/resize:fit:300/0*SWSvNr3OBhLp5XGx.png)