Notes on building Rails6 / PostgreSQL with Docker Compose

1. Preparation

Prepare the following files. After that, please change "app" as appropriate.


FROM ruby:2.6.6

RUN curl -sS | apt-key add - \
    && echo "deb stable main" | tee /etc/apt/sources.list.d/yarn.list

RUN apt-get update -qq && apt-get install -y nodejs postgresql-client yarn && apt-get install -y vim
RUN mkdir /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN bundle install
COPY . /app

COPY /usr/bin/
RUN chmod +x /usr/bin/

CMD ["rails", "server", "-b", ""]


source ''
gem 'rails', '6.0.3'

Gemfile.lock (empty)

set -e
rm -f /app/tmp/pids/
exec "[email protected]"


version: '3'
    image: postgres
      - ./volumes/db/log:/var/log/postgresql
      - POSTGRES_PASSWORD=password
    build: .
    command: bash -c "rm -f tmp/pids/ && bundle exec rails s -p 3000 -b ''"
      - .:/app
      - EDITOR=vim
      - "3000:3000"
      - db

Change the db password accordingly.

2. Build

docker-compose run rails rails new . --force --database=postgresql
docker-compose build

3. Database


default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgres
  password: password
  pool: 5

  <<: *default
  database: app_development

  <<: *default
  database: app_test

  <<: *default
  database: app_production
  username: app
  password: <%= ENV['APP_DATABASE_PASSWORD'] %>

Change the db password accordingly. Keep in mind that it should be combined with docker-compose.yml.

docker-compose up -d
docker-compose run rails rails db:create

4. Done

Access the following and if the usual "Yay! You're on Rails!" Is displayed, you're done.


Recommended Posts

Notes on building Rails6 / PostgreSQL with Docker Compose
Building Rails 6 and PostgreSQL environment with Docker
Error encountered with notes when deploying docker on rails
Build Rails environment with Docker Compose
Create Rails 6 + MySQL environment with Docker compose
Try building Express + PostgreSQL + Sequelize with Docker [Part 2]
Introducing Rspec with Ruby on Rails x Docker
python notes on docker
Rails deploy with Docker
Try building Express + PostgreSQL + Sequelize with Docker [Part 1]
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
Run Rails whenever with docker
[Docker] Rails 5.2 environment construction with docker
[Docker] Use whenever with Docker + Rails
I made a development environment with rails6 + docker + postgreSQL + Materialize.
Create Rails5 and postgresql environment with Docker and make pgadmin available
Measures for permissions when building MySQL with Docker on WSL2
Rails + MySQL environment construction with Docker
Node.js environment construction with Docker Compose
Use Docker Compose on Windows 10 Home
Rails on Docker environment construction procedure
[Environment construction with Docker] Rails 6 & MySQL 8
Deploy Rails on Docker to heroku
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Super beginner builds Rails6 + Postgresql environment with Docker to the end
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
How to install Pry after building Rails development environment with Docker
Building a haskell environment with Docker + VS Code on Windows 10 Home
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
Tutorial 1 for building apps with Rails (First steps to Yay! You're on Rails!)
[Ruby on Rails] View test with RSpec
Rails environment construction with Docker (personal apocalypse)
[Rails] How to use rails console with docker
Deploy to heroku with Docker (Rails 6, MySQL)
[Now] Let's Redmine with Docker Compose with Let's Encrypt
[Ruby on Rails] Controller test with RSpec
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Build a local development environment for Rails tutorials with Docker (Rails 6 + PostgreSQL + Webpack)
[Ruby on Rails] Model test with RSpec
Try using Kong + Konga with Docker Compose.
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Build an environment with Docker on AWS
When building rails6 environment on Ubuntu, it gets stuck with bundle install
Launched Redmine with Docker on Raspberry Pi 3
Run Ubuntu + ROS with Docker on Mac
How to build Rails 6 environment with Docker
A memorandum when building an environment with Ruby3.0 x Rails6.1 x Docker x CentOS Stream
Build a development environment for Docker + Rails6 + Postgresql
Try running MPLS-VPN with FR Routing on Docker
[Rails] rails new to create a database with PostgreSQL
Environment construction command memo with Docker on AWS
Publish the app made with ruby on rails
Try running OSPF with FR Routing on Docker
Building OpenPose (Pytorch_Realtime_Multi-Person_Pose_Estimation) environment on Docker: training part
Incorporate Docker into your Ruby on Rails portfolio!
Update container image with KUSANAGI Runs on Docker
[Rails] Procedure for linking databases with Ruby On Rails
How to use docker compose with NVIDIA Jetson
Determine the current page with Ruby on Rails
[Rails] How to build an environment with Docker
[Ruby on Rails] Upload multiple images with refile