ruby-on-rails - 使用 docker-compose 在添加/删除新 gem 后运行 bundle install
问题描述
我是 docker 新手,正在尝试将 docker 与我的 rails 应用程序集成。我在关注这个文档
我能够设置服务,但我遇到了问题。
每当我将 Gem 添加到我的 Gemfile 时,我都会docker-compose up
出错
sidekiq_1 | bundler: failed to load command: sidekiq (/usr/local/bundle/bin/sidekiq)
sidekiq_1 | /usr/local/bundle/gems/bundler-2.2.3/lib/bundler/resolver.rb:309:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'awesome_print' in any of the gem sources listed in your Gemfile. (Bundler::GemNotFound)
Dockerfile
FROM ruby:3.0.0-alpine3.12
ENV BUNDLER_VERSION=2.2.3
RUN apk add --update --no-cache \
binutils-gold \
build-base \
curl py-pip \
curl \
file \
g++ \
gcc \
git \
less \
libstdc++ \
libffi-dev \
libc-dev \
linux-headers \
libxml2-dev \
libxslt-dev \
libgcrypt-dev \
make \
netcat-openbsd \
nodejs \
openssl \
pkgconfig \
python3 \
tzdata \
yarn
RUN gem install bundler -v 2.2.3
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle check || bundle install
COPY package.json yarn.lock ./
RUN yarn install --check-files
COPY . ./
ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]
码头工人-compose.yml
version: '3.6'
services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: sna-main
depends_on:
- redis
ports:
- "3000:3000"
volumes:
- .:/app
- gem_cache:/usr/local/bundle/gems
- node_modules:/app/node_modules
environment:
RAILS_ENV: development
redis:
image: redis:5.0.7
sidekiq:
build:
context: .
dockerfile: Dockerfile
depends_on:
- app
- redis
volumes:
- .:/app
- gem_cache:/usr/local/bundle/gems
- node_modules:/app/node_modules
environment:
RAILS_ENV: development
entrypoint: ./entrypoints/sidekiq-entrypoint.sh
volumes:
gem_cache:
node_modules:
如果有人可以帮助我了解每次 Gemfile 发生变化时如何运行捆绑安装,那就太好了。
从文档中我了解到,因为我们正在缓存 Gems,所以如果我们添加/删除新的 gem,我们需要显式地删除卷。
我确实通过运行删除了卷docker-compose down -v
。它删除了卷,但仍然出现相同的错误。
解决方案
这有可能是因为 docker-compose 缓存了您的图像;您需要重新构建docker-compose up --build
以反映 docker-compose 中的图像更改。
推荐阅读
- numpy - 这个等式中的@是什么意思?
- ssis - 根据文件日期选择加载excel文件
- react-native - 不变违规元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件)
- android - Android Studio Proguard 配置文件
- regex - 使用正则表达式获取所有 HTML 标记之间的所有数字
- excel - Issue with VB macros in Excel not selecting the correct cells
- c# - 使用 newsoft.json 进行序列化和反序列化
- powershell - PowerShell Get-ChildItem with variable and string
- windows - 将新行添加到文本文件时运行 Windows 命令?
- r - 从一列名称中创建一列首字母作为R中的字符串