Dockerfile For Rails Backend
A quick summary of Dockerfile For Rails Backend
Dockerfile for Rails Backend
This is the base Dockerfile can be used to serve Rails application. Based on Debian. Average size is about 750 Mb.
It can be adjusted with Postgres Client Version, like 9.6, 10 or 11. Bundle version 2 is used.
Dockerfile
FROM ruby:2.6.1-slim-stretch
RUN apt-get update -qq && apt-get install --no-install-recommends -y \
build-essential \
patch \
ruby-dev \
zlib1g-dev \
liblzma-dev \
libxml2 \
libxml2-dev \
libpq-dev \
default-libmysqlclient-dev \
imagemagick \
git \
wget \
gnupg2 \
curl \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch"-pgdg main | tee /etc/apt/sources.list.d/pgdg.list \
&& apt-get update -qq && apt-get install --no-install-recommends --no-upgrade -y \
# postgresql-11 \
postgresql-client-11 \
&& rm -rf /var/lib/apt/lists/*
# && apt-get clean autoclean \
# && apt-get autoremove -y \
# && rm -rf \
# /var/lib/apt \
# /var/lib/dpkg \
# /var/lib/cache \
# /var/lib/log
RUN mkdir /opt/app
COPY ./config/entrypoint.sh /usr/bin/entrypoint.sh
RUN chmod +x /usr/bin/entrypoint.sh
WORKDIR /opt/app
RUN gem install bundler -v 2.0.1
ADD Gemfile* /opt/app/
RUN bundle install
COPY . /opt/app
EXPOSE 3000
#RUN $BUNDLE_PATH/bin/rails --version
Entrypoint.sh file
#!/bin/sh
set -e
cd /opt/app
export PGHOST=postgres
echo "$DB_HOST:5432:$DB_NAME:$DB_USER:$DB_PASSWORD" > ~/.pgpass
chmod 600 ~/.pgpass
rails db:migrate
rails db:seed
bundle exec puma -b tcp://0.0.0.0:3000 -e ${RAILS_ENV} -C /opt/app/config/puma.rb
ln -sf /proc/1/fd/1 /opt/app/log/${RAILS_ENV}.log