ruby-on-rails - 在构建过程中使用Dockerfile “Could not locate gemfile”在Rails上安装ruby

标签 ruby-on-rails ruby docker dockerfile

我有一项学校任务需要我这样做:

You are going to create your first Dockerfile to containerize Rails applications. That’s a special configuration: this particular Dockerfile will be generic, and called in another Dockerfile, that will look something like this:


FROM ft-rails:on-build
EXPOSE 3000
CMD ["rails", "s", "-b", "0.0.0.0", "-p", "3000"]

Your generic container should install, via a ruby container, all the necessary dependencies and gems, then copy your rails application in the /opt/app folder of your container. Docker has to install the appropriate gems when it builds, but also launch the migrations and the db population for your application. The child Dockerfile should launch the rails server (see example below). If you don’t know what commands to use, it’s high time to look at the Ruby on Rails documentation.



现在我的Dockerfile看起来像这样:
FROM ruby

RUN apt-get update -y && apt-get upgrade -y && apt-get install -y sqlite3 build-essential nodejs libpq-dev
RUN gem update && gem install rails && gem install bundler
RUN mkdir /opt/app

ONBUILD WORKDIR /opt/app/
ONBUILD ADD . /opt/app

ONBUILD EXPOSE 3000
ONBUILD RUN bundle install
ONBUILD RUN rake db:setup
ONBUILD RUN rake db:seed

当我构建此Dockerfile时,它工作正常。
当我回到作业中给出的通用dockerfile并尝试构建该文件时,出现错误:
Could not locate Gemfile
The command '/bin/sh -c bundle install' returned a non-zero code: 10

我不是Rails上的 ruby 专家,并且刚刚开始将其用于此任务。我不知道我在做什么错或如何解决这个问题,并且一直在网上寻找答案而没有成功...
任何帮助都非常欢迎!

最佳答案

构建它时,请确保您位于Rails项目的根文件夹中。您应该已经在此文件夹中运行rails new your-project-name来生成此文件。

命令ONBUILD ADD . /opt/app将递归地将当前文件夹复制到Docker镜像中,因此它必须已经包含Gemfile和Rails项目的所有其他部分。

关于ruby-on-rails - 在构建过程中使用Dockerfile “Could not locate gemfile”在Rails上安装ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57822842/

相关文章:

ruby - 如何在 ruby​​/bash 脚本中杀死生成的子进程

ruby - 如何最好地在两个 float 之间的范围内创建一个随机 float

ruby - 迭代嵌套哈希并修改值

elasticsearch - boot2docker在本地主机上访问elasticsearch

c# - 命令 '/bin/sh -c dotnet restore ./DockerTestDebian.csproj' 返回非零代码 : 1

ruby-on-rails - ruby rails : Routing for a tree hierarchy of places

mysql - 在 RoR 中连接表

ruby-on-rails - 有_许多 :through association error 'could not find the source association'

ruby-on-rails - 如何检查字符串中的值是否为 IP 地址

mysql - 连接到外部MYSQL Docker容器