Skip to content

Instantly share code, notes, and snippets.

@davidleandro
Created August 1, 2023 20:22
Show Gist options
  • Save davidleandro/73ddc23d913194dd833864172465687e to your computer and use it in GitHub Desktop.
Save davidleandro/73ddc23d913194dd833864172465687e to your computer and use it in GitHub Desktop.
Estudologia Docker config
version: "3.8"
services:
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/estudologia-api
ports:
- "3000:3000"
depends_on:
- redis
env_file:
- .env
redis:
image: "redis:alpine"
# Base image:
FROM ruby:3.1.3
ARG _WORKDIR=/estudologia-api
ARG PORT=3000
# Update and install JavaScript Runtime and PostgreSQL dependencies
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
# Create a new directory for the application in the container
RUN mkdir ${_WORKDIR}
# Set our working directory inside the image
WORKDIR ${_WORKDIR}
# Copy Gemfile and Gemfile.lock to the working directory
COPY Gemfile ${_WORKDIR}/Gemfile
COPY Gemfile.lock ${_WORKDIR}/Gemfile.lock
# Install the app dependencies
RUN bundle install
# Copy the rest of the application into the working directory
COPY . /estudologia-api
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
# Expose port in the container
EXPOSE ${PORT}
# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0"]
#!/bin/bash
set -e
# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid
# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec bundle exec rails db:migrate &
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment