...

/

Starting a Postgres Server

Starting a Postgres Server

Here we will start to learn about the database that we want to add in our app.

Postgres server

We want to run a Postgres server for our Rails app to use. The process is very similar to adding Redis. In the previous chapter, we started by familiarizing ourselves with how to run the Redis server with docker run. However, now that we have had some experience with adding a service, we can jump straight to setting up Postgres directly with Compose.

Modification of docker-compose.yml

Let’s add Postgres to our docker-compose.yml file:

Press + to interact
version: '3'
services:
web:
build: .
ports:
- "3000:3000"
volumes:
- . :/usr/src/app
redis:
image: redis
database:
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: some-long-secure-password
POSTGRES_DB: myapp_development

Explanation

We have defined a new database service using the official postgres image. We are relying on this image’s default CMD ...