【发布时间】:2018-07-05 21:16:02
【问题描述】:
我目前正在通过 docker 设置 Rails 样板。当我尝试运行 docker build . 时,出现以下错误:
Step 5/8 : COPY Gemfile /app/
COPY failed: stat /var/lib/docker/tmp/docker-builder090950451/Gemfile: no such file or directory
我正在按照documentation 中的说明进行操作,但我仍然无法构建映像。
这是我的 Dockerfile
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR /app
# Copy the existing Gemfile
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
# Install Gems
RUN bundle install
COPY . /app
我还有以下docker-compose.yml 文件:
version: '3'
services:
db:
image: postgres # 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
我通过运行docker-compose run web rails new app --force --database=postgresql 生成了 Rails 应用程序,它确实生成了带有 Gemfile 的 rails 应用程序,如下图所示。
但是在生成 rails 应用程序并运行 docker-compose build 后,我收到以下错误:
db uses an image, skipping
Building web
Step 1/7 : FROM ruby:2.5
---> 55fb4a37704e
Step 2/7 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
---> Using cache
---> afb6f347904c
Step 3/7 : WORKDIR /app
---> Using cache
---> 1fdbd260685d
Step 4/7 : COPY Gemfile /app/Gemfile
ERROR: Service 'web' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder885442968/Gemfile: no such file or directory
【问题讨论】:
-
您的 Dockerfile 在您的应用目录中吗?在 VSCode 目录结构中无法正常查看。
-
@johnharris85 它在应用程序目录中
-
这就是问题所在,默认情况下,构建上下文是您的 Dockerfile 所在的位置,而 Gemfile 不存在其中。我去了你正在关注的文档,它们在同一个目录中。
-
但是如果子文件夹
app没有Gemfile怎么办?在app文件夹中是controllers、helpers和models所在的位置。 -
你说得对,它奏效了。我不明白如何
标签: ruby-on-rails docker docker-compose