【问题标题】:Rails run with puma in dockerfile and enable httpsRails 在 dockerfile 中使用 puma 运行并启用 https
【发布时间】:2022-01-29 17:18:27
【问题描述】:

这是一个用于 ruby​​ on rails 项目的 Dockerfile 示例。 我想用 ssl 密钥和证书运行它

RUN apt-get update -yqq && apt-get install -y npm && npm install -g yarn
RUN apt-get install -y ruby-full
RUN apt install libsqlite3-dev
RUN gem install rails --version=6.1
RUN mkdir /var/app
WORKDIR /var/app
COPY . .
RUN bundle install --without development test

RUN npm install --force
RUN export SECRET_KEY_BASE=...............................
EXPOSE 3000
EXPOSE 80
EXPOSE 443
EXPOSE 8443
RUN rails webpacker:install
#RUN rake assets:clean
RUN rake assets:precompile
CMD rails s -b 0.0.0.0 -e production

【问题讨论】:

    标签: ruby-on-rails ruby docker http https


    【解决方案1】:
    FROM ruby:3.0.2
    RUN apt-get update -yqq && apt-get install -y npm && npm install -g yarn
    RUN apt-get install -y ruby-full
    RUN apt install libsqlite3-dev
    RUN gem install rails --version=6.1
    RUN mkdir /var/app
    WORKDIR /var/app
    COPY . .
    RUN bundle install --without development test
    
    RUN npm install --force
    RUN export SECRET_KEY_BASE=...............................
    EXPOSE 3000
    EXPOSE 80
    EXPOSE 443
    EXPOSE 8443
    RUN rails webpacker:install
    #RUN rake assets:clean
    RUN rake assets:precompile
    CMD puma -b 'ssl://0.0.0.0:8443?key=yourkey.key&cert=yourcertificat.pem&verify_mode=none' -b 'tcp://0.0.0.0:80' -e production
    

    在 config/environment/production.rb 添加:config.force_ssl=true

    您可以 freessl 为您的域获取 ssl 密钥和证书; https://freessl.org/ 要在您的虚拟机或实例上运行它:docker run -d -p 443:443 -p 80:80 yourimage:tag

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-08
      • 2019-07-26
      • 2018-12-12
      • 2015-06-23
      • 2016-08-25
      • 2014-10-03
      • 2018-04-15
      相关资源
      最近更新 更多