Wednesday, 22 June 2022

Rails7

Rails7 on podman は、もっと簡単な Dockerfile と Gemfile を見つけてきたら動きました。
( podman image name を間違えて ruby 2.7 でやっていた)

podman -network host だと、localhost:port で外からもアクセスできる。ま、制限もできるんだろけど。
なので、割と簡単に Rails7 を動かせる。VM 抜きで。

bundle install を何回もするの変なんだけど。

cat Dockerfile

  FROM ruby:3.1

  RUN apt -y update && apt -y upgrade && apt -y install vim zsh
  RUN apt install iproute2 -y
  RUN apt install iputils-ping

  RUN mkdir /myapp
  WORKDIR /myapp
  COPY Gemfile /myapp/Gemfile
  COPY Gemfile.lock /myapp/Gemfile.lock
  RUN bundle install
  RUN bundle exec rails new blog
  WORKDIR /myapp/blog
  RUN bundle install

  # COPY . /myapp
  # 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 3000

  # Start the main process.
  CMD ["bundle","exec","rails", "server", "-b", "0.0.0.0"]

cat Gemfile

  source "https://rubygems.org"
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  ruby "3.1.2"

  # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
  gem "rails", github: "rails/rails", branch: "7-0-stable"

No comments: