[英]Yarn packages out of date when running Rails app in Docker
I start my Rails 6 app as Docker containers, but when it starts the Rails server, it keeps giving the error:我将我的 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).
So why is this not working?那么为什么这不起作用呢? I have that command in the Dockerfile and also that check is disabled in
webpacker.yml
.我在 Dockerfile 中有该命令,并且在
webpacker.yml
中禁用了该检查。
I build it with docker-compose up --build
and then it doesn't seem to give errors.我用
docker-compose up --build
构建它,然后它似乎没有给出错误。 When I start it with docker-compose up
, it will return the erorr when the Rails server is started.当我用
docker-compose up
启动它时,它会在 Rails 服务器启动时返回错误。 Here are the relevant files:以下是相关文件:
Dockerfile: 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: 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
docker-compose.yml: docker-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:
It seems to me like you are building your app correctly in the image in the /app directory.在我看来,您正在 /app 目录中的图像中正确构建您的应用程序。 But afterward in your docker-compose you mount a local volume over your built /app directory, thereby losing your built /app folder contents.
但是之后在您的 docker-compose 中,您在构建的 /app 目录上安装了一个本地卷,从而丢失了构建的 /app 文件夹内容。 Try removing the mounted volume
'.:/app'
.尝试删除已安装的卷
'.:/app'
。
In your docker-compose.yml, you can also do this to avoid rebuilding everytime time.在您的 docker-compose.yml 中,您也可以这样做以避免每次都重新构建。 Then, you can just do
docker-compose up
然后,你可以做
docker-compose up
command: bash -c "bundle install && yarn install --check-files && bundle exec rails s -p 3000 -b '0.0.0.0'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.