Docker Ruby 2.7 on Rails 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.9" | |
services: | |
db: | |
image: postgres | |
volumes: | |
- ./tmp/db:/var/lib/postgresql/data | |
environment: | |
POSTGRES_PASSWORD: password | |
web: | |
build: . | |
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" | |
volumes: | |
- .:/myapp | |
ports: | |
- "3000:3000" | |
depends_on: | |
- db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby 2.7 on Rails 6 | |
FROM ruby:2.7.4 | |
# Rails6ではnodejsとyarnはwebpackをインストールする際に必要 | |
# yarnパッケージ管理ツールをインストール | |
# 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 | |
RUN apt-get update -qq && apt-get install -y nodejs build-essential libpq-dev postgresql-client yarn | |
WORKDIR /myapp | |
COPY Gemfile /myapp/Gemfile | |
COPY Gemfile.lock /myapp/Gemfile.lock | |
RUN bundle install | |
RUN yarn install --check-files | |
RUN bundle exec rails webpacker:install | |
# コンテナー起動時に毎回実行されるスクリプトを追加 | |
COPY entrypoint.sh /usr/bin/ | |
RUN chmod +x /usr/bin/entrypoint.sh | |
ENTRYPOINT ["entrypoint.sh"] | |
EXPOSE 3000 | |
# イメージ実行時に起動させる主プロセスを設定 | |
CMD ["rails", "server", "-b", "0.0.0.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Rails に対応したファイル server.pid が存在しているかもしれないので削除する。 | |
rm -f /myapp/tmp/pids/server.pid | |
# コンテナーのプロセスを実行する。(Dockerfile 内の CMD に設定されているもの。) | |
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'rails', '6.1.4' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment