ruby-on-rails - Docker Compose 找不到 Gemfile 或 .bundle/ 目录
问题描述
当我运行时,docker-compose up -d
我收到以下错误:
web_1 | Could not locate Gemfile or .bundle/ directory
但是正在创建图像。我想要一个 Rails 应用程序,并且让 Docker 文件位于 Rails 应用程序之外。我有以下Dockerfile
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR /app
COPY ./app/Gemfile Gemfile
# Install Gems
RUN bundle install
ADD . /app
在docker-compose.yml
文件中,我有以下配置:
version: '3'
services:
db:
image: postgres:9.6.1 # To Edit - Default is postgresql.
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- db
对于 Gemfile,我有以下代码:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use postgresql as the database for Active Record
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
我不确定它是否与 Rails 或 Ruby 版本有关。我还看到,一旦我进入容器并运行,Gemfile 就在那里,ls
所以并不是没有 Gemfile。
root@ab38d643df47:/app# ls
Dockerfile Gemfile Gemfile.lock README.md app docker-compose.yml
解决方案
尝试这个:
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR app
COPY Gemfile Gemfile
# Install Gems
RUN bundle install
ADD . app
推荐阅读
- azure - 从 Azure 表存储到 Cosmos DB 表存储的数据迁移,
- windows - “混帐添加。” 不工作
- c# - Fluent API - 在一个实体中配置同一类的多个实例
- python - HDF5 转数据帧格式
- python - 使用单个管道预处理具有不同特征类型的数据集
- uwp - [UWP][C#] 我的应用程序不健康
- eclipse - STM32 GNU ARM 链接器:使用 eclipse 对函数()的未定义引用
- javascript - getCredentialsForIdentity - ResourceNotFoundException
- c# - 调用应用程序 Windows 任务计划程序时调用 WebClient.DownloadFile 不会下载,但手动运行时会下载?
- android - 如何使用 Android 的 MediaBrowserService 服务 MediaStore 歌曲?