当我在我的Docker容器中启动Rails控制台时,我遇到了错误Could not find ..... in locally installed gems
,并列出了所有的gems。
rails s
或rails routes
正常工作,构建时没有错误。
运行bundle install
没有改变任何东西。
我找到的解决方法是使用docker-compose run web bundle install --binstubs
我在所有gems捆绑安装问题中没有发现同样的问题,我想知道我的Docker文件有什么问题。
Dockerfile:
# Use the official Ruby 2.5.0 image as the parent image
FROM ruby:2.5.0-slim
# Install dependencies
RUN apt-get update -qq \
&& apt-get install -y \
# Needed for certain gems
build-essential \
shared-mime-info \
# Needed for postgres gem
libpq-dev \
# Needed for mysql
default-libmysqlclient-dev \
# Needed for redis
libssl-dev \
# Needed for elastic search
libcurl4-openssl-dev \
# Needed for foreman
procps
# Set the working directory to /app
WORKDIR /app
# Copy the Gemfile and Gemfile.lock into the image and install gems
ENV BUNDLER_VERSION=2.3.26
COPY Gemfile Gemfile.lock ./
RUN gem install bundler -v $BUNDLER_VERSION && bundle install --jobs 20 --retry 5
# Copy the rest of the application code into the image
COPY . .
# Expose port 3000 for the Rails app to listen on
EXPOSE 3000
# Start the Rails app with Puma
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]
Docker-compose:
version: '3.3'
services:
db:
image: mysql/mysql-server:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: app_api_dev
MYSQL_USER: app_api
MYSQL_PASSWORD: app_api
volumes:
- ./tmp/db:/var/lib/mysql
ports:
- "3306:3306"
redis:
image: redis
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- db
- redis
environment:
DATABASE_HOST: db
DATABASE_USERNAME: app_api
DATABASE_PASSWORD: app_api
DATABASE_NAME: app_api_dev
/app/vendor
目录是否安装了Gem包?由于您的volumes:
隐藏了/app
中的所有内容,该块也将隐藏该目录。您不需要那个volumes:
块(应用程序代码已正确复制到映像中),删除它可能会有所帮助。 - David Mazegem info
命令的输出结果。 - anothermh