My Dockerfile
FROM ruby:2.6.3-alpine
RUN apk add --no-cache build-base tzdata postgresql-dev postgresql-client
# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
ENV APP_PATH /app
RUN mkdir -p $APP_PATH
WORKDIR $APP_PATH
COPY Gemfile $APP_PATH
COPY Gemfile.lock $APP_PATH
RUN bundle install
COPY . $APP_PATH
EXPOSE 3000
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]
I notice installing postgresql-dev will cause installing openssl-dev.
Anyway, run docker-compose up will output
$ docker-compose up
Building sidekiq
Step 1/12 : FROM ruby:2.6.3-alpine
---> 6ddb199f039f
Step 2/12 : RUN apk add --no-cache build-base tzdata postgresql-dev postgresql-client bash
---> Running in 386a4486295f
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
(1/28) Upgrading libcrypto1.1 (1.1.1c-r0 -> 1.1.1d-r2)
(2/28) Upgrading libssl1.1 (1.1.1c-r0 -> 1.1.1d-r2)
(3/28) Installing bash (5.0.0-r0)
Executing bash-5.0.0-r0.post-install
(4/28) Installing binutils (2.32-r0)
(5/28) Installing libmagic (5.37-r1)
(6/28) Installing file (5.37-r1)
(7/28) Installing isl (0.18-r0)
(8/28) Installing libgomp (8.3.0-r0)
(9/28) Installing libatomic (8.3.0-r0)
(10/28) Installing mpfr3 (3.1.5-r1)
(11/28) Installing mpc1 (1.1.0-r0)
(12/28) Installing gcc (8.3.0-r0)
(13/28) Installing musl-dev (1.1.22-r3)
(14/28) Installing libc-dev (0.7.1-r0)
(15/28) Installing g++ (8.3.0-r0)
(16/28) Installing make (4.2.1-r2)
(17/28) Installing fortify-headers (1.1-r0)
(18/28) Installing build-base (0.5-r1)
(19/28) Installing libedit (20190324.3.1-r0)
(20/28) Installing db (5.3.28-r1)
(21/28) Installing libsasl (2.1.27-r4)
(22/28) Installing libldap (2.4.48-r0)
(23/28) Installing libpq (11.6-r0)
(24/28) Installing postgresql-client (11.6-r0)
(25/28) Installing openssl-dev (1.1.1d-r2)
in ubuntu, it is forever frozen for step (25/28) Installing openssl-dev (1.1.1d-r2).
In mac, it shows
(25/27) Installing postgresql-libs (11.6-r0)
ERROR: Failed to create usr/lib/libssl.a: No error information
ERROR: openssl-dev-1.1.1d-r2: BAD signature
Is there anything wrong? Also, how can I get a bit more detailed info/log why it cannot install openssl-dev?
Related
I am trying to install gosu gem using docker but I am getting the following error:
/usr/local/bundle/gems/gosu-1.4.5/lib/gosu.so: warning: undefining the allocator of T_DATA class swig_runtime_data
/usr/local/bundle/gems/gosu-1.4.5/lib/gosu/swig_patches.rb:18:in `initialize': Could not initialize SDL Video: No available video device (RuntimeError)
I have tried modifying the dockerfile or installing additional libraries
For example:
ENV XDG_RUNTIME_DIR=/tmp
or
apt install xorg-dev
Here is my Dockerfile
from ruby:latest
WORKDIR /usr/src/app
COPY . .
RUN apt-get update && apt-get -qq -y install curl && apt-get install -y build-essential libsdl2-dev libgl1-mesa-dev libopenal-dev libgmp-dev libfontconfig1-dev xorg-dev && gem install gosu
ENV XDG_RUNTIME_DIR=/tmp
EXPOSE 3000
It depends on the SDL library to display graphics. Add this to docker file,
RUN apt-get update && apt-get install -y libsdl2-dev
RUN gem install gosu
Refer this for the set of libraries to be further added for docker if the above command don't solve the issue. unable to install Gosu library in Ruby in Linux .
I can not install ruby's gems on alpine docker image. I've tried different approaches from other questions to solve ERROR: While executing gem ... (Gem::FilePermissionError), but there are solutions either for Ubuntu or for Mac OS.
Part of docker file code:
RUN set -ex \
&& apk add --no-cache --update ruby ruby-dev ruby-bundler \
&& gem install --no-document --source https://rubygems.org --version 3.6.6 inspec
OUTPUT:
+ apk add --no-cache --update ruby ruby-dev ruby-bundler
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/11) Installing yaml (0.2.5-r0)
(2/11) Installing ruby-libs (2.7.3-r1)
(3/11) Installing ruby (2.7.3-r1)
(4/11) Installing ruby-etc (2.7.3-r1)
(5/11) Installing ruby-io-console (2.7.3-r1)
(6/11) Installing ruby-bundler (2.2.20-r0)
(7/11) Installing libgmpxx (6.2.1-r0)
(8/11) Installing gmp-dev (6.2.1-r0)
(9/11) Installing libucontext (1.1-r0)
(10/11) Installing libucontext-dev (1.1-r0)
(11/11) Installing ruby-dev (2.7.3-r1)
Executing busybox-1.33.1-r2.trigger
Executing glibc-bin-2.33-r0.trigger
/usr/glibc-compat/sbin/ldconfig: /usr/glibc-compat/lib/ld-linux-x86-64.so.2 is not a symbolic link
OK: 1409 MiB in 141 packages
+ gem install --no-document --source https://rubygems.org --version 3.6.6 inspec
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory.
The command '/bin/sh -c set -ex && apk add --no-cache --update ruby ruby-dev ruby-bundler && gem install --no-document --source https://rubygems.org --version 3.6.6 inspec' returned a non-zero code: 1 ```
This seems to be a problem with docker versions earlier than 20.10.4, and at the time of writing this, DockerHub runs an older version.
Option 1:
If you have control over the version of your docker engine, upgrade it to the latest version (comments suggest at least version 20.10.4).
Option 2:
Use FROM alpine:3.13.
With the latest alpine (3.14) it breaks.
Option 3:
Use the official ruby alpine image. I tested with FROM ruby:3-alpine.
References:
The issue opened on alpine/aports
The relevant release notes section for alpine 3.14
Using docker and trying to build an image but I get the above error when I bundle due to the nokogiri gem issue
My Docker file is
RUN apt update
RUN apt install -y ruby
RUN gem install bundler
RUN cd /usr/src/app
WORKDIR /web
ADD Gemfile /web/
RUN bundle
However, when I RUN bundle at the end ^ I get the following error:
...
Fetching mini_portile2 2.4.0
Installing mini_portile2 2.4.0
Fetching nokogiri 1.10.2
Installing nokogiri 1.10.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.2/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20190414-8-1rrc2i8.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.10.2 for
inspection.
Results logged to
/var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.2/gem_make.out
An error occurred while installing nokogiri (1.10.2), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.10.2' --source
'http://rubygems.org/'` succeeds before bundling.
In Gemfile:
capybara was resolved to 3.16.2, which depends on
xpath was resolved to 3.2.0, which depends on
nokogiri
The command '/bin/sh -c bundle' returned a non-zero code: 5
Add the following line to the Dockerfile, it will handle the dependency
RUN apt install -y build-essential patch ruby-dev zlib1g-dev liblzma-dev
just before the RUN bundle command
and then run the build again
docker build -t dock .
...
Fetching nokogiri 1.10.2
Installing nokogiri 1.10.2 with native extensions
Fetching rack 2.0.7
Installing rack 2.0.7
...
Bundle complete! 7 Gemfile dependencies, 33 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Removing intermediate container 146ce309d0a5
---> cd36c7c1e577
Successfully built cd36c7c1e577
Successfully tagged dock:latest
...
Thanks to https://nokogiri.org/tutorials/installing_nokogiri.html for this find.
For alpine
RUN set -x \ && apk upgrade --no-cache \ && apk add --no-cache
--virtual build-dependencies \
build-base \ && apk add --no-cache \
libxml2-dev \
libxslt-dev \ && gem install nokogiri \
-- --use-system-libraries \
--with-xml2-config=/usr/bin/xml2-config \
--with-xslt-config=/usr/bin/xslt-config \ && apk del build-dependencies
My Doc Dockerfile has FROM Ubuntu:18.04
I want to use ruby so i did
gem install bundler
However when I try to
bundle
I get an error with nokogiri
Installing nokogiri 1.10.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.2/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20190414-288-1mfprtc.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.10.2 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.2/gem_make.out
An error occurred while installing nokogiri (1.10.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.10.2' --source 'http://rubygems.org/'` succeeds before bundling.
You have a dependency called nokogiri that has external dependency, usually it's libxml and libxslt.
All you need to do is apt get install libxml2-dev libxslt1-dev
Here's a working example of a Ruby Dockerfile
FROM ruby:2.6.2
RUN apt-get update -qq && apt-get install -y build-essential
RUN apt-get install -y libxml2-dev libxslt1-dev
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY Gemfile* /usr/src/app/
RUN bundle install -j3
ADD . /usr/src/app
ENTRYPOINT ["bundle", "exec"]
CMD ["rails", "server"]
I am trying to create a docker image using a ruby app using the docker file:
FROM jruby:latest
# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \
build-essential \
nodejs \
git \
ruby-dev \
gcc \
libffi-dev \
make \
zlib1g-dev \
libssl-dev \
libreadline6-dev \
libyaml-dev
# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.
RUN mkdir -p /app
WORKDIR /app
# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5
# Copy the main application.
COPY . ./
# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000
but i get an error when i'm trying to build this docker image
the gem install RedCloth is giving an error saying that I need to install development tools first.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /usr/local/bundle/gems/RedCloth-4.3.2/ext/redcloth_scan
/opt/jruby/bin/jruby -r ./siteconf20181127-31-1zsapr.rb extconf.rb
checking for main() in -lc... RuntimeError: The compiler failed to generate an
executable file.
You have to install development tools first.
How do I fix this?
jruby has often has trouble with native extensions. In this case, the redcloth gem used to provide precompiled binaries for jruby but as of version 4.3 (the version you're attempting to install) they are no longer available:
Precompiled binary gems are provided for JRuby and Win32 platforms prior to version 4.3.
According to the README, you should be able to run rake compile to build the binaries. This may be a lot of extra work in your Docker image to make work, so I would recommend trying an older version of redcloth that has the binaries you need first. (keep in mind, the 4.2 series was released in 2011 and may not have the functionality you need)