docker and docker-compose installed
Put Gemfile, Gemfile.lock, Dockerfile, Docker-compose.yml under ~ / Desktop / product-register.
FROM ruby:2.5
RUN apt-get update && apt-get install -y \
build-essential \
libpg-dev \
nodejs \
postgresql-client \
yarn
WORKDIR /product-register
COPY Gemfile Gemfile.lock /product-register/
RUN bundle install
version: '3'
services:
web:
build: . //image If you get an image:Image name
ports:
- '3000:3000'
volumes:
- '.:/product-register'
tty: true
stdin_open: true
Note: Indentation and space are severe
source 'https://rubygems.org'
gem 'rails', '~> 5.2'
$ docker-compose up -d
$ docker-compose exec web bash
:/product-register# rails new . --force --database=postgresql -skip-bundle //gemfile is updated
$ docker-compose down //Drop the container once to update the gemfile
$ docker-compose up --build -d To use the newly built image of dockerfile--Add build
$ docker-compose exec web bash //Enter again
:/product-register# rails s -b 0.0.0.0 //I get an error because the db is not set yet
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: db
user: postgres
port: 5432
password: <%= ENV.fetch("DATABASE_PASSWORD") %>
version: '3'
volumes:
db-data: //I am making docker volume
services:
web:
build: .
ports:
- '3000:3000'
volumes:
- '.:/app'
environment:
- 'DATABASE_PASSWORD=postgres'
tty: true
stdin_open: true
depends_on:
- db
links:
- db
db:
image: postgres
volumes:
- 'db-data:/var/lib/postgresql/data' //I'm mounting the docker volume I made above
environment:
- 'POSTGRES_PASSWORD=postgres' //Seems to have been needed recently
Recommended Posts