ruby-on-rails - 在 Docker 中运行 Rails 应用程序时,纱线包已过期
问题描述
我将 Rails 6 应用程序作为 Docker 容器启动,但是当它启动 Rails 服务器时,它不断给出错误:
warning Integrity check: System parameters don't match
website_1 | error Integrity check failed
website_1 | error Found 1 errors.
website_1 |
website_1 |
website_1 | ========================================
website_1 | Your Yarn packages are out of date!
website_1 | Please run `yarn install --check-files` to update.
website_1 | ========================================
website_1 |
website_1 |
website_1 | To disable this check, please change `check_yarn_integrity`
website_1 | to `false` in your webpacker config file (config/webpacker.yml).
那么为什么这不起作用呢?我在 Dockerfile 中有该命令,并且在webpacker.yml
.
我用它构建它,docker-compose up --build
然后它似乎没有给出错误。当我用 启动它时docker-compose up
,它会在 Rails 服务器启动时返回错误。以下是相关文件:
Dockerfile:
FROM ruby:2.6.5-slim
LABEL maintainer="John van Arkelen <johnvanarkelen@fastmail.com>"
RUN apt-get update -qq && apt-get install -y curl build-essential libpq-dev postgresql postgresql-contrib
RUN mkdir /app
RUN mkdir -p /usr/local/nvm
WORKDIR /app
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v
ENV BUNDLE_PATH /gems
RUN gem install bundler -v 2.0.2
COPY Gemfile Gemfile.lock package.json yarn.lock ./
RUN bundle install
RUN npm install -g yarn
COPY . /app
RUN yarn install --check-files
webpacker.yml:
default: &default
source_path: app/javascript
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
check_yarn_integrity: false
webpack_compile_output: false
码头工人-compose.yml:
version: '2'
services:
postgres:
image: 'postgres:10.3-alpine'
volumes:
- 'postgres:/var/lib/postgresql/data'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password123
POSTGRES_DB: qd_development
env_file:
- '.env'
redis:
image: 'redis:4.0-alpine'
command: redis-server --requirepass password123
volumes:
- 'redis:/data'
website:
depends_on:
- 'postgres'
- 'redis'
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
ports:
- '3000:3000'
volumes:
- '.:/app'
- gem_cache:/gems
environment:
DATABASE_HOST: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password123
POSTGRES_DB: qd_development
env_file:
- '.env'
volumes:
redis:
postgres:
gem_cache:
解决方案
在我看来,您正在 /app 目录中的图像中正确构建您的应用程序。但是之后在您的 docker-compose 中,您在构建的 /app 目录上挂载了一个本地卷,从而丢失了构建的 /app 文件夹内容。尝试删除已安装的卷'.:/app'
。