Skip to content

Instantly share code, notes, and snippets.

@LukasPol
Last active November 8, 2021 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LukasPol/52bf1fba4dcf66a6d2da39694cd657cc to your computer and use it in GitHub Desktop.
Save LukasPol/52bf1fba4dcf66a6d2da39694cd657cc to your computer and use it in GitHub Desktop.
docker Rails + postgres

Criar cada arquivo + Gemfile.lock - config/database.yml

docker-compose build

docker-compose run web rails new . --force --no-deps --database=postgresql

Substitui o config/database.yml criado pelo que está descrito aqui

docker-compose up

docker-compose exec web bash

default: &default
adapter: postgresql
host: <%= ENV["POSTGRES_HOST"] %>
encoding: unicode
pool: 5
username: <%= ENV["POSTGRES_USER"] %>
password: <%= ENV["POSTGRES_PASSWORD"] %>
template: template0
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
production:
<<: *default
database: myapp_production
password: <%= ENV["POSTGRES_PASSWORD_PRODUCTION"] %>
version: '3.7'
services:
db_pg:
image: postgres:12.6
volumes:
- postgres:/var/lib/postgresql/data
env_file: .env
ports:
- "5433:5432"
app:
build: .
depends_on:
- db_pg
ports:
- "3000:3000"
volumes:
- .:/myapp
env_file: .env
command: bash -c "sleep 100000"
volumes:
postgres:
FROM ruby:2.7.2
RUN apt-get update -yqq && apt-get install -y build-essential libpq-dev nodejs
## install yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install -y yarn && rm -rf /var/lib/apt/lists/*
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
##
RUN gem install bundler:2.0.2
RUN bundle check || bundle install
COPY . /myapp
## Add Endpoint
COPY docker-entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
# EXPOSE 3000
#!/bin/bash
set -e
rm -f tmp/pids/server.pid
bundle check || bundle install
yarn install
exec "$@"
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '~> 6.0.2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment