I've only used mysql with docker and it took a long time, so I wrote it so that I can see it later. I also included pgadmin because it is convenient.
docoker-docker so you don't have to rails s after compose up-compose.I wrote in yml so that it will be done automatically with command.
 I don't usually need to recreate the container, so I'm assuming that I will do it with `` `docker-compose start / stop```.
#### **`Dockerfile`**
```dockerfile
FROM ruby:2.6
RUN apt-get update -y && \
    apt-get install  -y nodejs
COPY Gemfile /Gemfile
COPY Gemfile.lock /Gemfile.lock
RUN gem install bundler
RUN bundle install
docker-compose.yml
version: "3"
services:
  db:
    image: postgres
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: root
    volumes:
      - "./postgres-data:/var/lib/postgresql/data"
  pgadmin4:
    image: dpage/pgadmin4:4.2
    ports:
      - 80:80
    volumes:
      - ./docker/pgadmin4:/var/lib/pgadmin
    environment:
      PGADMIN_DEFAULT_EMAIL: root
      PGADMIN_DEFAULT_PASSWORD: root
    depends_on:
      - db
  web:
    build: .
    volumes:
      - ".:/app"
    ports:
      - "3000:3000"
    tty: true
    depends_on:
      - db
    working_dir: "/app"
    command: "rails s -b 0.0.0.0"
mysql and database.yml are different, and I was addicted to writing something like develop here. I had to write it properly in default.
config/database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  #Here and there
  username: root
  password: root
  host: db
Reference site Persistence of connection server settings of pgadmin4 / docker -Qiita
Write the Dockerfile and docker \ -compose \ .yml for rails5 -Qiita
Recommended Posts