Skip to content

Instantly share code, notes, and snippets.

@gitDbits
Last active November 12, 2019 01:21
Show Gist options
  • Select an option

  • Save gitDbits/f1237e85c18b6a2bdc1e2f1ca45df08b to your computer and use it in GitHub Desktop.

Select an option

Save gitDbits/f1237e85c18b6a2bdc1e2f1ca45df08b to your computer and use it in GitHub Desktop.
Configure initial Rails + Docker + Docker-compose
## Guide docker compose install
https://docs.docker.com/compose/install/
## Command initial
docker run -it --rm --user "$(id -u):$(id -g)" -v "$PWD":/usr/src/app -w /usr/src/app rails rails new --skip-bundle my_app --database=postgresql
## Create Dockerfile
FROM ruby:2.5.3
# Instala as nossas dependencias
RUN apt-get update && apt-get install -qq -y --no-install-recommends \
build-essential nodejs libpq-dev
# Seta nosso path
ENV INSTALL_PATH /usr/src/app
# Cria nosso diretório
RUN mkdir -p $INSTALL_PATH
# Seta o nosso path como o diretório principal
WORKDIR $INSTALL_PATH
# Copia o nosso Gemfile para dentro do container
COPY Gemfile ./
# Instala as Gems
RUN bundle install
# Copia nosso código para dentro do container
COPY . .
# Roda nosso servidor
CMD puma -C config/puma.rb
# create docker-compose.yml
version: '2'
services:
postgres:
image: 'postgres:9.5'
volumes:
- 'postgres:/var/lib/postgresql/data'
website:
depends_on:
- 'postgres'
build: .
ports:
- '3000:3000'
volumes:
- '.:/usr/src/app'
volumes:
postgres:
## Run build
docker-compose build
## Configure config/database.yml
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: postgres
user: postgres
development:
<<: *default
database: my_app_development
test:
<<: *default
database: my_app_test
production:
<<: *default
database: my_app_production
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment