Docker 运行 给出错误“初始化”:参数数量错误(给定 2,预期 1)(ArgumentError)
Docker run gives error `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)
我一直在尝试创建 docker 图像和 运行 ruby 文件
以下是创建docker图像的代码
FROM ruby:3
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && \
bundle config --global frozen 1 && \
bundle install
RUN gem install extensions
COPY app.rb config.ru database.rb utils.rb thin.rb ./
EXPOSE 8080
CMD exec thin -R config.ru -p 8080 start
我也试过 CMD bundle exec thin start
而不是上面的最后一个命令。
然后我执行下面的命令来构建镜像
sudo docker build -t project3 .
并且构建成功。
但是当我运行docker run -p 8080:8080 project3
我收到以下错误
mayuresh@mayuresh-Lenovo-ideapad-330-15IKB:~/Softwares/CS291_project3$ sudo docker run -p 8080:8080 project3
/usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/regular.rb:22:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in `new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in `block in new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/equality_map.rb:43:in `fetch'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in `new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann.rb:67:in `new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann.rb:70:in `block in new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann.rb:70:in `map'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann.rb:70:in `new'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:1641:in `compile'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:1629:in `compile!'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:1271:in `error'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:1831:in `<class:Base>'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:889:in `<module:Sinatra>'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:22:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/main.rb:26:in `<module:Sinatra>'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/main.rb:1:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra.rb:1:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
from /app/app.rb:1:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from config.ru:1:in `block in <main>'
from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
from config.ru:1:in `new'
from config.ru:1:in `<main>'
from /usr/local/bundle/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `eval'
from /usr/local/bundle/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `load'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/controllers/controller.rb:182:in `load_rackup_config'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/controllers/controller.rb:72:in `start'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/runner.rb:203:in `run_command'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/runner.rb:159:in `run!'
from /usr/local/bundle/gems/thin-1.7.2/bin/thin:6:in `<top (required)>'
from /usr/local/bundle/bin/thin:23:in `load'
from /usr/local/bundle/bin/thin:23:in `<main>'
<internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- sinatra (LoadError)
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /app/app.rb:1:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from config.ru:1:in `block in <main>'
from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
from config.ru:1:in `new'
from config.ru:1:in `<main>'
from /usr/local/bundle/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `eval'
from /usr/local/bundle/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `load'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/controllers/controller.rb:182:in `load_rackup_config'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/controllers/controller.rb:72:in `start'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/runner.rb:203:in `run_command'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/runner.rb:159:in `run!'
from /usr/local/bundle/gems/thin-1.7.2/bin/thin:6:in `<top (required)>'
from /usr/local/bundle/bin/thin:23:in `load'
from /usr/local/bundle/bin/thin:23:in `<main>'
此外,我想提一下,之前我已经 docker 化了许多具有类似 docker 文件的项目,但我不明白这种方法可能会带来什么问题。
感谢帮助!
release history for mustermann
表示在 v1.1.0
中添加了对 ruby v3.0.0
的支持。
您正在使用 ruby v3.0.0
和 mustermann v1.0.3
。
要么将 ruby 降级到 2.7,要么将 mustermann 升级到 1.1.0+
我一直在尝试创建 docker 图像和 运行 ruby 文件
以下是创建docker图像的代码
FROM ruby:3
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && \
bundle config --global frozen 1 && \
bundle install
RUN gem install extensions
COPY app.rb config.ru database.rb utils.rb thin.rb ./
EXPOSE 8080
CMD exec thin -R config.ru -p 8080 start
我也试过 CMD bundle exec thin start
而不是上面的最后一个命令。
然后我执行下面的命令来构建镜像
sudo docker build -t project3 .
并且构建成功。
但是当我运行docker run -p 8080:8080 project3
我收到以下错误
mayuresh@mayuresh-Lenovo-ideapad-330-15IKB:~/Softwares/CS291_project3$ sudo docker run -p 8080:8080 project3
/usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/regular.rb:22:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in `new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in `block in new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/equality_map.rb:43:in `fetch'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann/pattern.rb:59:in `new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann.rb:67:in `new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann.rb:70:in `block in new'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann.rb:70:in `map'
from /usr/local/bundle/gems/mustermann-1.0.3/lib/mustermann.rb:70:in `new'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:1641:in `compile'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:1629:in `compile!'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:1271:in `error'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:1831:in `<class:Base>'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:889:in `<module:Sinatra>'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/base.rb:22:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/main.rb:26:in `<module:Sinatra>'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra/main.rb:1:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /usr/local/bundle/gems/sinatra-2.0.7/lib/sinatra.rb:1:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'
from /app/app.rb:1:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from config.ru:1:in `block in <main>'
from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
from config.ru:1:in `new'
from config.ru:1:in `<main>'
from /usr/local/bundle/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `eval'
from /usr/local/bundle/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `load'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/controllers/controller.rb:182:in `load_rackup_config'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/controllers/controller.rb:72:in `start'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/runner.rb:203:in `run_command'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/runner.rb:159:in `run!'
from /usr/local/bundle/gems/thin-1.7.2/bin/thin:6:in `<top (required)>'
from /usr/local/bundle/bin/thin:23:in `load'
from /usr/local/bundle/bin/thin:23:in `<main>'
<internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- sinatra (LoadError)
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /app/app.rb:1:in `<top (required)>'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from config.ru:1:in `block in <main>'
from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
from /usr/local/bundle/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
from config.ru:1:in `new'
from config.ru:1:in `<main>'
from /usr/local/bundle/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `eval'
from /usr/local/bundle/gems/thin-1.7.2/lib/rack/adapter/loader.rb:33:in `load'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/controllers/controller.rb:182:in `load_rackup_config'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/controllers/controller.rb:72:in `start'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/runner.rb:203:in `run_command'
from /usr/local/bundle/gems/thin-1.7.2/lib/thin/runner.rb:159:in `run!'
from /usr/local/bundle/gems/thin-1.7.2/bin/thin:6:in `<top (required)>'
from /usr/local/bundle/bin/thin:23:in `load'
from /usr/local/bundle/bin/thin:23:in `<main>'
此外,我想提一下,之前我已经 docker 化了许多具有类似 docker 文件的项目,但我不明白这种方法可能会带来什么问题。
感谢帮助!
release history for mustermann
表示在 v1.1.0
中添加了对 ruby v3.0.0
的支持。
您正在使用 ruby v3.0.0
和 mustermann v1.0.3
。
要么将 ruby 降级到 2.7,要么将 mustermann 升级到 1.1.0+