简体   繁体   English

Ruby Dockerfile 显示用法和选项,而不是启动 rails 服务器

[英]Ruby Dockerfile show usage and options rather than starting rails server

The problem问题

I have created my own dockerfile to spin up a rails api loosely based on https://docs.docker.com/samples/rails/我创建了自己的 dockerfile 以基于https://docs.docker.com/samples/rails/松散地启动 Rails api

Everything builds fine and the image creates successfully but when I start the image I get the output below on how to use the rails command in my Docker logs.一切都构建良好,并且图像创建成功,但是当我启动图像时,我得到以下关于如何在我的 Docker 日志中使用rails命令的输出。

See the following image:见下图:

码头工人日志

This hasn't given me too much to go on from a debugging aspect so I was curious if anyone had experienced this before.这并没有让我从调试方面继续下去,所以我很好奇是否有人以前经历过这种情况。 Ill attach my Dockerfile and other related files below for context.我将在下面附上我的 Dockerfile 和其他相关文件以获取上下文。 For reference API contains my Gemfile.供参考的 API 包含我的 Gemfile。

Associated Files相关文件

Dockerfile: Dockerfile:

FROM ruby:2.7

WORKDIR /api
COPY /api/ .

RUN bundle install

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
RUN ls
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

Entrypoint.sh入口点.sh

#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

Gemfile:宝石文件:

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "2.7.6"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.3"

# Use postgresql as the database for Active Record
gem "pg", "~> 1.4.1"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
# gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem "rack-cors"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

I've tried to do my own digging but googling combinations of the above description tend to lead to Docker's base documentation rather than anything useful.我尝试自己进行挖掘,但谷歌搜索上述描述的组合往往会导致 Docker 的基本文档,而不是任何有用的东西。

Any assistance would be greatly appreciated.任何帮助将不胜感激。 Ill stick around if any follow up/context is needed.如果需要任何跟进/上下文,我会坚持下去。 Thank you in advance!先感谢您!

Usually such output appears when use rails command in folder that doesn't contain rails project通常在不包含 rails 项目的文件夹中使用rails命令时会出现这样的输出

Looks like problem is here看起来问题就在这里

WORKDIR /api
COPY /api/ .

Usually Dockerfile is located in the root of project通常Dockerfile位于项目的根目录

So you need to copy all files from project root to work directory of container所以你需要将所有文件从项目根目录复制到容器的工作目录

WORKDIR /api
COPY . .

This directives mean that in your container /api folder will contain rails code该指令意味着在您的容器/api文件夹中将包含 rails 代码

And if so, then the command rails server -b 0.0.0.0 will not have to cause such an output in the console如果是这样,那么命令rails server -b 0.0.0.0将不必在控制台中导致这样的输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM