当前位置: 首页 > 知识库问答 >
问题:

Docker,Rails 3.2,依赖关系问题

翟永春
2023-03-14

一切似乎运行良好,包括运行docker-compose up-d--build,然后执行到rails容器中,捆绑安装,然后尝试运行rails s。然后我得到以下结果:

    /usr/local/rvm/rubies/ruby-2.4.1/bin/ruby: warning: shebang line ends with \r may cause a problem
/usr/local/rvm/gems/ruby-2.4.1/gems/sinatra-1.4.6/lib/sinatra/base.rb:1225: warning: constant ::Fixnum is deprecated
/usr/local/rvm/gems/ruby-2.4.1/gems/sinatra-1.4.6/lib/sinatra/base.rb:1225: warning: constant ::Fixnum is deprecated
/usr/local/rvm/gems/ruby-2.4.1/gems/sinatra-1.4.6/lib/sinatra/base.rb:1225: warning: constant ::Fixnum is deprecated
/usr/local/rvm/gems/ruby-2.4.1/gems/builder-3.0.4/lib/builder/xchar.rb:111: warning: constant ::Fixnum is deprecated
/usr/local/rvm/gems/ruby-2.4.1/gems/sinatra-1.4.6/lib/sinatra/base.rb:1225: warning: constant ::Fixnum is deprecated
/usr/locfrom /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:251:in `block in require'e -- guard/guard (LoadError)
        from /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-3.2.22.5/lib/active_support/dependencies.rb:251:in `require'endency'
        from /usr/local/rvm/gems/ruby-2.4.1/gems/bundler-1.16.0.pre.3/lib/bundler/runtime.rb:97:in `require''
        from /usr/local/rvm/gems/ruby-2.4.1/gems/bundler-1.16.0.pre.3/lib/bundler/runtime.rb:74:in `block in require'n require'
        from /usr/local/rvm/gems/ruby-2.4.1/gems/bundler-1.16.0.pre.3/lib/bundler/runtime.rb:67:in `require'
        from /var/www/html/config/application.rb:13:in `<top (required)>'/bundler.rb:114:in `require'
        from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-3.2.22.5/lib/rails/commands.rb:53:in `block in <top (required)>'
        from /usr/local/rvm/gems/ruby-2.4.1/gems/railties-3.2.22.5/lib/rails/commands.rb:50:in `<top (required)>'
        from script/rails:6:in `<main>''

任何关于如何前进的想法都将不胜感激;我已经被困在这上面很久了。

以下是我的Gemfile、docker-compose.yml、database.yml和每个Docker容器的Dockerfiles:

version: '3'

services:
  web:
    build: 
      context: .
    ports:
      - "8080:3000"
      - "4443:443"
    volumes:
      - ./:/var/www/html
    environment:
      - ALLOW_OVERRIDE=true
    command: tail -f /dev/null
    container_name: hl_web
    links:
    - db
  db:
    image: postgres:9.3.17
    volumes:
      - "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock"
      - "db-data:/var/lib/postgresql/data"
    container_name: hl_db

volumes:
  db-data:
defaults: &defaults
  adapter: postgresql
  # template: template_postgis
  encoding: unicode
  pool: 5
  username: root
  password:
  host: db

development:
  <<: *defaults
  database: realty_development

test:
  <<: *defaults
  database: realty_test

staging:
  <<: *defaults
  database: realty_development

production:
  <<: *defaults
  database: realty_production
# Latest Ubuntu LTS
FROM ubuntu:12.04

RUN apt-get -y update && apt-get -y upgrade
RUN apt-get -y install --fix-missing curl git wget libpq-dev node libpq-dev vim

# Install mpapis
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
RUN \curl -sSL https://get.rvm.io | bash -s stable --ruby

# Need to add RVM to the path
ENV PATH /usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN /bin/bash -l -c 'source /etc/profile.d/rvm.sh'
RUN /bin/bash -l -c "rvm install 2.1.2"
RUN /bin/bash -l -c "rvm use 2.1.2"
RUN /bin/bash -l -c "gem install rails -v 4.2.2"

# Copy # Heroku installer to opt and run it
#COPY ./docker_config/install-ubuntu.sh /opt/install-ubuntu.sh
#WORKDIR /opt
#RUN sh install-ubuntu.sh

# Heroku installer
RUN /bin/bash -l -c 'echo "deb http://toolbelt.heroku.com/ubuntu ./" > /etc/apt/sources.list.d/heroku.list'
RUN \wget -O- https://toolbelt.heroku.com/apt/release.key | apt-key add -
RUN apt-get -y update
RUN apt-get install -y heroku-toolbelt

# Change back to project root and run bundle
#WORKDIR /var/www/html
#RUN /bin/bash -l -c "bundle install"

# make bundler a default gem
RUN echo bundler >> /usr/local/rvm/gemsets/global.gems
# source rvm in every shell
RUN sed -i '3i . /etc/profile.d/rvm.sh\n' ~/.profile
# setup some default flags from rvm (auto install, auto gemset create, quiet curl)
RUN echo "rvm_install_on_use_flag=1\nrvm_gemset_create_on_use_flag=1\nrvm_quiet_curl_flag=1" > ~/.rvmrc

# Copy over the site vhosts
# COPY ./docker_settings/apache_web.conf /etc/apache2/sites-available/000-asite.com.conf
# RUN ln -s /etc/apache2/sites-available/000-asite.com.conf /etc/apache2/sites-enabled/000-asite.com.conf
# RUN rm /etc/apache2/sites-enabled/000-default.conf

# # Link ssl
# RUN ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf

# # Enable modules
# RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
# RUN ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled/ssl.load
# RUN ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled/ssl.conf
# RUN ln -s /etc/apache2/mods-available/socache_shmcb.load /etc/apache2/mods-enabled/socache_shmcb.load

# # Create some directories so Apache doesn't fallover
# RUN mkdir /var/www/html/public

# # Restart apache to load changes
# RUN service apache2 restart

# # We need to make some directories writable by apache before docker mounts it
# RUN chown -R www-data:www-data /var/www/html

# # Donwload composer. Install to /usr/bin
# WORKDIR /opt/composer
# RUN curl -sS https://getcomposer.org/installer | php
# RUN cp composer.phar /usr/bin/composer

# # make the work directory the web root dir
# WORKDIR /var/www/html
# 

# interactive shell by default so rvm is sourced automatically
#ENTRYPOINT /bin/bash -l

CMD ["/bin/bash -l"]

用于postgres的Dockerfile

# Latest Ubuntu LTS
FROM ubuntu:12.04

RUN apt-get -y update 
#&& apt-get -y upgrade
RUN apt-get -y install --fix-missing curl git wget libpq-dev node libpq-dev vim

#Install postgres
RUN locale-gen en_US.UTF-8

RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/postgresql.list'
RUN \wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN apt-get -y update
RUN apt-get -y install postgresql-9.3 postgresql-9.3-postgis-2.1
#RUN apt-get -y install postgis

RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf

# Expose the PostgreSQL port
EXPOSE 5432

# Add VOLUMEs to allow backup of config, logs and databases
VOLUME  ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]

RUN service postgresql start

#ENTRYPOINT /bin/bash
#CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf", "start"]

GEMFILE:

source 'https://rubygems.org'

gem 'rails', '~> 3.2.17'

# http://rack.github.com/
gem 'rack', '~> 1.4.5'

# To redirect trailing slashes to have no trailing slashes
gem 'rack-rewrite'

platforms :ruby do
  # Unicorn is a forking webserver
  gem 'unicorn'

  # Terminate out-of-control unicorns
  gem 'unicorn-worker-killer'
end

platforms :mswin do
  gem 'thin'
end

# dependencies for the redirector app:
gem 'sinatra-subdomain'
gem 'postrank-uri'

# Used for date queries
gem 'groupdate'

# Used to inject data into javascript DOM
gem 'gon'

# Used to connect to Amazon for sitemap_generator gem
gem 'fog'

# Used for background workers/concurrent tasks.
gem 'sidekiq'
gem 'sidekiq-failures'

# Next two gems are for sidekiq monitor
gem 'slim', '>= 1.1.0'
# if you require 'sinatra' you get the DSL extended to Object
gem 'sinatra', '>= 1.3.0', require: nil

# Used for long running jobs to display progress
gem 'ruby-progressbar'

# Cloudinary API - image processing and CDN
gem 'cloudinary'

# Performance monitoring / exception tracking
gem 'newrelic_rpm'
gem 'newrelic-rake'

# Convert an address into lat/lon coordinate pair
gem 'geocoder'

# Yesmail
gem 'yesmail', git: 'git://github.com/apartmentlist/yesmail.git'
gem 'yesmail2', git: 'git://github.com/apartmentlist/yesmail2.git'
gem 'log_mixin', git: 'git://github.com/apartmentlist/log_mixin.git'

# Captcha support through recaptcha
gem 'recaptcha', :require => 'recaptcha/rails'

# xml generation
# IMPORTANT: Put nokogiri before pg in your Gemfile
# https://github.com/sparklemotion/nokogiri/issues/742
# http://stackoverflow.com/questions/6802410/warning-nokogiri-was-built-against-libxml-version-2-7-8-but-has-dynamically-lo#answer-10912948
# http://stackoverflow.com/questions/11668604/mountain-lion-libxml-nokogiri
gem "nokogiri", ">= 1.6.7.rc"

# Postgres / Postgis gems
gem 'pg'

# Eventually, this gem needs upgrading as this branch is no longer supported
gem 'postgis_adapter', git: 'git://github.com/nofxx/postgis_adapter.git'

# HTTP/api stuff (lead posting)
gem 'httparty', '~> 0.10.0'

# HTTP library
gem 'faraday'

gem 'aws-sdk'

gem 'json'
gem 'psych', '~> 2.0.5'

# hiredis is a high performance redis driver that supports timeouts on a socket
gem 'hiredis'
gem 'redis', require: ['redis/connection/hiredis', 'redis']
gem 'redis-rails'

# Templates/Frontend
gem 'haml', '>= 3.0.0'
gem 'haml-rails'
gem 'kramdown'
gem 'haml-kramdown'

gem 'jquery-rails', '~> 2.1.4'
gem 'bourbon'
gem 'meta-tags', require: 'meta_tags'

# Detect mobile/tablet browsers
gem 'mobile-fu'

# P3P header generation so IE can load cookies in remote iFrames
gem 'rack-p3p'

# Timestamp scopes
gem 'timestamp_scopes', '~> 0.0.1'

# Twitter bootstrap
gem 'bootstrap-sass', '~> 2.3.2.1'
gem 'jquery-validation-rails'

# Pagination
gem "kaminari"

# Easy generation of sitemaps with upload to S3
gem 'sitemap_generator'

# Show the Rails environment on the Rails console prompt
gem 'marco-polo'

# Shorthand for update_all in batches
gem 'update_in_batches'

# Cleanup HTML to have a black or white list of tags
gem 'sanitize'

# A/B testing framework designed to work with Rails
gem 'split', require: 'split/dashboard'

# Used to include wordpress blog site that is hosted on a different server
gem "rack-reverse-proxy", require: "rack/reverse_proxy"

# Heroku specific
group :edge, :staging, :production do
  # Overwrite heroku's rails_log_stdout to support tagged logging
  gem 'rails_log_stdout', '~> 0.1.1'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', '3.2.5'
  gem 'coffee-rails'
  gem 'uglifier', '>= 1.0.3'
end

group :development, :test do
  gem 'awesome_print'
  gem 'quiet_assets'
  gem "rspec-rails", "~> 2.13.0"
  gem "capybara", "~> 2.1.0"
  gem "poltergeist", "~> 1.3.0"
  gem 'rspec-given'
  gem 'rr'
  gem 'shoulda-matchers'
  gem 'capybara-screenshot'
  gem 'factory_girl_rails'
  gem 'forgery'
  gem 'simplecov', :require => false
  gem 'simplecov-rcov', :require => false
  gem 'dotenv-rails'
  gem "rspec-instafail", "~> 0.2.4"
  gem "show_me_the_cookies"

  # Not removing these commented out gem lines so that we can enable profiling
  # in the near future per instructions at:
  # http://guides.rubyonrails.org/v3.2.13/performance_testing.html
  # enable next line for profiling
  # gem 'ruby-prof'
  # enable next 2 lines for profiling with rails 4
  # gem 'rails-perftest'
   gem 'test-unit'
end

group :development do
  gem 'annotate'
  gem 'foreman'
  gem 'guard'
  gem 'guard-bundler'
  gem 'guard-livereload'
  gem 'guard-pow'
  gem 'guard-rspec'
  gem 'guard-spork'
  gem 'spork-rails'
  gem 'growl'
  gem 'powify'
  gem 'yard'
  gem 'stack_rescue'
  # gem 'pry-rails'
  # The heroku toolbelt is required for the heroku rake tasks.
  # https://toolbelt.heroku.com/
  # gem 'heroku'
end

共有1个答案

赵高韵
2023-03-14

您的配置有很多问题,包括您对Ruby的选择。

这个错误源于使用Ruby2.4和Rails3.3。ruby支持的最高版本是2.2,这是StackOverflow上的一个问题。这里是原始答案的链接,这里是应用于您的配置的答案本身。看看这篇博文中的引用:

Rails 3.2.22包括来自3-2Stable分支的所有提交。这意味着现在Rails3.2支持Ruby2.2。

还有一件令人费解(难以理解)的事情是docker-compose和dockerfiles之间的脱节。例如,您定义了自己的postgres图像,但使用官方的postgres:9.3.17。我知道您可能会使用您在环境中预先构建的图像,但这不是使用Docker-Compose时的标准做法。如果Dockerfile是自定义图像,建议使用compose中的Dockerfile。这允许您在动态中进行更改,并防止其他人假设您使用了官方的postgres图像。不管怎样,这种脱节都是令人困惑的。

解决方案

第一步:为您的配置选择基本图像。

    null
  1. 安装我们的宝石和其他依赖项

就是这样。说真的。我们不需要做的是:

  1. 安装rvm,docker已经隔离了我们的应用程序,所以安装它并使用Gemsets是没有意义的。
  2. 安装heroku工具带。我真的不明白为什么你需要heroku工具带,如果你需要,它可以放在另一个容器里。如果您部署到heroku,那么它最好与您的应用程序映像分开。
  3. 安装ruby 2.1.2和Rails4。我不明白你为什么要这么做。您明确表示需要Rails3.2和Ruby2.2.
  4. 安装apache,它应该在不同的容器上运行,如果是在生产环境中,则应该在主机上运行。在开发过程中,不应运行apache容器。
FROM ruby:2.2

# Set a working directory, I am partial to /src but choose whatever you like
WORKDIR /src

# Copy gemfile to pre-install gems (Allows us to quickly test if all is working well)
COPY Gemfile /src/Gemfile

# Install any library dependencies here like so after which you should
# install/update bundler then install gems from Gemfile
RUN apt-get -y update \
    && apt-get -y install curl \
                       git \
                       wget \
                       libpq-dev \
                       node \
                       libpq-dev \
                       vim \
                       /*whatever else you need*/ \
    && rm -rf /var/lib/apt/lists/* \  #  To preserve syntax highlighting */  
    && gem install bundler \
    && bundle install 

# Copy source files to image for flexibility later on, for example if you would like to push a bundled image to a registry or run it without compose
COPY . /src

# Define /src as a volume
VOLUME /src

# Use expose to show which port should be exposed to the host or other containers
EXPOSE 3000

# Run rails s in the foreground on container launch
CMD ["rails", "s", "-b 0.0.0.0", "-p 3000 "]
    null

然后,您的撰写文件看起来应该与原始文件非常相似。

version: '3'

volumes:
  # We'll define a volume that will store the data from the postgres databases:
  postgres-data:
    driver: local

services:
  # Our PostgreSQL service:
  postgres:
    image: mdillon/postgis:9.3

    ports:
      # We'll bind our host's port 5432 to postgres's port 5432, so we can use
      # our database IDEs with it:
      - 5432:5432

    volumes:
      # Mount the DB dumps folder into the container, to be able to create & access database dumps:
      - ./db/dumps:/db/dumps
      # Mount out tmp folder, we might want to have access to something there during development:
      - ./tmp:/tmp
      # We'll mount the 'postgres-data' volume into the location Postgres stores it's data:
      - postgres-data:/var/lib/postgresql/data
      # We'll mount the postgres socket just like before         
      - /var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock

    environment:
      POSTGRES_PASSWORD: password

  rails:
    build:
      context: .
      dockerfile: Dockerfile

    entrypoint: rails s -p 3000 -b 0.0.0.0

    volumes:
      # Mount our app code directory (".") into our app containers at the
      # "/src" folder:
      - .:/src    

    # Keep the stdin open, so we can attach to our app container's process and do things such as
    # byebug, etc:
    stdin_open: true

    # Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
    tty: true

    # Link to our postgres and redis containers, so they can be visible from our
    # app containers:
    links:
      # We'll include a link to the 'db' (postgres) container, making it visible from the container
      # using the 'db.local' hostname (which is not necessary, but I'm doing it here to
      # illustrate that you can play with this):
      - postgres:db.local

    environment:
      # Run the app in the 'development' environment:
      RACK_ENV: development
      RAILS_ENV: development

    depends_on:
      - postgres

在运行该配置时,docker-compose up应该无缝地运行,但在此之前,您应该首先配置database.yml

第四步:database.yml

defaults: &defaults
  adapter: postgresql
  # template: template_postgis
  encoding: unicode
  pool: 5
  username: root
  password: password
  host: db.local

development:
  <<: *defaults
  database: realty_development

test:
  <<: *defaults
  database: realty_test

staging:
  <<: *defaults
  database: realty_development

production:
  <<: *defaults
  database: realty_production
 类似资料:
  • 编写的PHP扩展需要需要依赖另外一个扩展,在PHP-X中可以调用Extension->require来实现。 PHPX_EXTENSION() { Extension *ext = new Extension("test", "0.0.1"); ext->require("swoole"); ext->require("sockets"); return ext;

  • 依赖关系 这是一个非常轻量级的模块,没有其他依赖项。希望大家在JVM或Android上使用以太坊的RLP编码的项目时会选择使用这个模块,而不再编写自己的实现。

  • 依赖关系 ABI一个非常轻量级的模块,唯一的第三方依赖是 Bouncy Castle,用于hash加密 (Spongy Castle on Android)。 最后希望java和安卓开发者,在JVM或Android上有以太坊ABI合作的项目时会选择使用这个模块,而不是再编写自己的实现。

  • 问题内容: 我有一个依赖关系如下: 当我部署一切正常时,这将拉下另一个引发ClassDefNotFound的依赖项。 我添加了两个依赖项,如下所示: 并且仍然面临着同样的问题,即:MVN带来下来不 我该如何解决? 编辑: 添加; 问题答案: 您可能有一个传递依赖项,另一个依赖项取决于您不需要的版本。 要获得所有直接和传递依赖关系的概述,请尝试: mvn依赖项:树 如果您发现同一依赖项的不同版本之间

  • 问题内容: 我正在运行一个依赖groovy 1.7-beta-1的项目。gmaven插件使用groovy 1.6版作为依赖项。在pom中,我在依赖性管理部分中将grooyv-all版本指定为: 但是,当我在调试模式下运行maven时,我看到groovy 1.6被用于对gmaven插件的依赖。我以为我的依赖项管理部分会重写此设置,因此它们都使用1.7-beta-1,但是由于常规版本不同,我遇到了错误

  • 使用Zookeeper依赖关系 Spring Cloud Zookeeper可以让您提供应用程序的依赖关系作为属性。作为依赖关系,您可以了解Zookeeper中注册的其他应用程序,您可以通过Feign(REST客户端构建器)以及Spring RestTemplate呼叫。 您还可以从Zookeeper依赖关系观察者功能中受益,这些功能可让您控制和监视依赖关系的状态,并决定如何处理。 如何激活Zoo