我使用的是 Mac,我想在 docker 上运行 Ruby On Rails 项目。 我的设置是:
Dockerfile
:
FROM ruby:2.7.2
RUN apt-get update -qq && apt-get install -y build-essential
RUN apt-get install -y libv8-dev
RUN apt-get install -y libpq-dev
RUN apt-get install -y libxslt-dev liblzma-dev patch git-core zlib1g-dev libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn
RUN gem install bundler
RUN gem install nokogiri --platform=ruby
RUN gem install libv8 -v '3.16.14.19' --source 'https://rubygems.org/'
ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install --no-deployment
ADD . $APP_HOME
docker-compose.yml
:
version: '3'
services:
db:
image: postgres
ports:
- "5440:5432"
environment:
POSTGRES_PASSWORD: password
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build: .
command: bin/rails server --port 3000 --binding 0.0.0.0
volumes:
- .:/myapp
ports:
- "3007:3000"
links:
- db
Gemfile
:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.2'
gem 'rails', '~> 6.1.3'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'therubyracer', platforms: :ruby
gem 'sass-rails', '>= 6'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
gem 'bootsnap', '>= 1.4.4', require: false
gem 'dotenv-rails'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "excon", "~> 0.79.0"
gem "activeadmin"
gem "devise"
gem "cancancan"
gem "haml-rails", "~> 2.0"
gem 'simple_token_authentication', '~> 1.0' # see semver.org
gem 'sidekiq'
gem 'sidekiq-client-cli'
gem 'whenever'
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'pry-byebug'
gem 'pry-doc'
gem 'pry-rails'
end
group :development do
gem 'web-console', '>= 4.1.0'
gem 'rack-mini-profiler', '~> 2.0'
gem 'listen', '~> 3.3'
gem 'spring'
gem 'capistrano', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano3-puma', require: false
end
group :test do
gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
gem 'webdrivers'
end
我尝试运行 docker build .
,但总是收到错误
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /usr/local/bundle/gems/libv8-3.16.14.19/ext/libv8
/usr/local/bin/ruby -I /usr/local/lib/ruby/2.7.0 -r
./siteconf20210323-5-xzbchb.rb extconf.rb
creating Makefile
Applying
/usr/local/bundle/gems/libv8-3.16.14.19/patches/disable-building-tests.patch
Applying
/usr/local/bundle/gems/libv8-3.16.14.19/patches/disable-werror-on-osx.patch
Applying
/usr/local/bundle/gems/libv8-3.16.14.19/patches/disable-xcode-debugging.patch
Applying
/usr/local/bundle/gems/libv8-3.16.14.19/patches/do-not-imply-vfp3-and-armv7.patch
Applying
/usr/local/bundle/gems/libv8-3.16.14.19/patches/do-not-use-MAP_NORESERVE-on-freebsd.patch
Applying /usr/local/bundle/gems/libv8-3.16.14.19/patches/do-not-use-vfp2.patch
Applying /usr/local/bundle/gems/libv8-3.16.14.19/patches/fPIC-for-static.patch
Compiling v8 for x64
Using python 2.7.16
Using compiler: c++ (GCC version 8.3.0)
Beginning compilation. This will take some time.
Building v8 with env CXX=c++ LINK=c++ /usr/bin/make x64.release
ARFLAGS.target=crs werror=no
GYP_GENERATORS=make \
build/gyp/gyp --generator-output="out" build/all.gyp \
-Ibuild/standalone.gypi --depth=. \
-Dv8_target_arch=x64 \
-S.x64 -Dv8_enable_backtrace=1
-Dv8_can_use_vfp2_instructions=true -Darm_fpu=vfpv2
-Dv8_can_use_vfp3_instructions=true -Darm_fpu=vfpv3 -Dwerror=''
make[1]: Entering directory
Gem files will remain installed in /usr/local/bundle/gems/libv8-3.16.14.19 for
inspection.
Results logged to
/usr/local/bundle/extensions/x86_64-linux/2.7.0/libv8-3.16.14.19/gem_make.out
An error occurred while installing libv8 (3.16.14.19), and Bundler cannot
continue.
Make sure that `gem install libv8 -v '3.16.14.19' --source
'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
therubyracer was resolved to 0.12.3, which depends on
libv8
所以请帮助我。