我有一项学校任务需要我这样做:
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/