このイメージを使い回せば次回からの環境構築が楽になると思っていろいろやってみたけど、ちょこちょこハマってしまいました。
ひとまず、Dockerfileとかいろいろ
APPNAMEは自分のアプリ名に打ち替え
FROM ruby:2.7.1
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 postgresql-client yarn
RUN mkdir /APPNAME
WORKDIR /APPNAME
COPY Gemfile /APPNAME/Gemfile
COPY Gemfile.lock /APPNAME/Gemfile.lock
RUN bundle install
COPY . /APPNAME
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=hogehoge
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/APPNAME
ports:
- "3000:3000"
depends_on:
- db
#!/bin/bash
set -e
# Remove a potentially pre-existing server.pid for Rails.
rm -f /uchinoko/tmp/pids/server.pid
# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"
source 'https://rubygems.org'
gem 'rails', '6.0.3.3'
Gemfile.lockはファイルだけ作成して中身は空っぽで。
そんで、
docker-compose build
docker-compose run web rails new . --force --no-deps --database=postgresql
rails newでできるファイルやディレクトリがすべてrootで出来上がってしまう。 ここがハマってしまった。
ちゃんとエラー文見てればすぐ分かったのに。
なので、
sudo chown -R hoge:hoge /APPNAME
これでOK
教訓教訓。