简体   繁体   中英

Docker image working on Ubuntu 16.04 but failing on Ubuntu 18.04

I thought docker images worked independent of the OS and did not need any dependencies installed on the OS itself.

I have a docker image built using the dockerfile:

FROM ubuntu:16.04

# Prepare to install Java for 'rjb' gem
RUN apt-get update && apt-get -y install software-properties-common && add-apt-repository ppa:webupd8team/java -y && apt-get update 

# Install Java 8 and accept the license by default (https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-16-04)
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections && apt-get -y install oracle-java8-installer && java -version 

# Set JAVA_HOME (should add in the docker startup script)
RUN echo 'export JAVA_HOME="/usr/lib/jvm/java-8-oracle"' >> /etc/environment && . /etc/environment && echo $JAVA_HOME 

ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

# Install curl, rvm, ruby 2.1.5p273, rails 4.2.6
RUN apt-get -y update && apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev && apt-get -y install wget && apt-get install -y ruby-full && ruby -v && gem install rails -v 4.2.6 && rails -v

# Install bundler, git
RUN gem install bundler && apt-get -y install git

ENV DEBIAN_FRONTEND noninteractive   

# Make sure 'bundle install' run successfully and set the git pre-commit hooks
RUN ["/bin/bash", "-c", "cd home && mkdir expertiza_developer && cd expertiza_developer && git clone https://github.com/expertiza/expertiza.git && cd expertiza && apt-get -y install ruby-dev && apt-get -y install make && apt-get install -y gcc make && apt-get install -y libmysqlclient-dev && apt-get install -y libpq-dev && bundle install && debconf-set-selections <<< 'mysql-server mysql-server/root_password password ' && debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password ' && apt-get -y install mysql-server && /etc/init.d/mysql start && cp config/database.yml.example config/database.yml && cp config/secrets.yml.example config/secrets.yml && mv ./hooks/pre-commit ./.git/hooks/pre-commit && chmod 755 ./.git/hooks/pre-commit"]

and using the following docker-compose file to run the image:

version: '3'

services:
  expertiza:
    image: winbobob/expertiza:test
    ports:
      - '3000:3000'
    volumes:
      - '.:/root/expertiza'
    depends_on:
      - scrubbed_db
      - redis
    links:
      - scrubbed_db
      - redis
    working_dir: /root/expertiza
    command: bundle exec thin start -p 3000
    environment:
      REDIS_HOST: redis

  scrubbed_db:
    image: mysql:5.7
    volumes:
      # https://stackoverflow.com/questions/25920029/setting-up-mysql-and-importing-dump-within-dockerfile
      - './docker/scrubbed_db:/docker-entrypoint-initdb.d'
    environment:
      MYSQL_ROOT_PASSWORD: expertiza

  redis:
    image: redis:alpine

This runs perfectly fine on an Ubuntu 16.04 box, but when I run this same image on an Ubuntu 18.04 box, I get the following error:

expertiza_1    | /var/lib/gems/2.3.0/gems/bundler-1.16.4/lib/bundler/spec_set.rb:91:in `block in materialize': Could not find rubyzip-1.2.2 in any of the sources (Bundler::GemNotFound)

Does anyone know why this is happening and how to fix it?

You are not specifying the version of the packages that you want installed with apt-get install . As a result, you're stuck with whatever version is available for those packages for the distribution that you're using.

In this case, you think you're installing Ruby 2.1.5 but on 16.04 you're actually installing Ruby 2.3.0 and on 18.04 you're installing Ruby 2.5.1 . Your RUN command includes ruby -v so check your build logs to confirm that you're not getting the version you expect.

Also, make sure gem install rubyzip -v 1.2.2 works as a RUN command, that rubyzip is defined in your Gemfile and the correct version is defined in Gemfile.lock, and that whatever gem server bundler is pointing to has a copy of the gem at that version.

Next, you're trying to use Rails 4.2.6 but Rails 4.2.6 is not compatible with Ruby 2.5.1. It's not compatible with 2.4 either. The first version of Rails 4 to support Ruby 2.4 was 4.2.8rc1 and the current version of Rails 4 is 4.2.10 .

Ensure that you are installing the correct versions of the packages that you need and that your applications and libraries are using compatible versions. Additionally, consider upgrading your version of Ruby as support of Ruby 2.1 has ended . (and it ended over a year ago)

Finally, consider using a Docker image that has Ruby already, rather than installing Ruby via apt-get . For example, the 2.3-stretch image gives you Debian stretch with Ruby 2.3's latest revision. Other versions are also available . The upside of using one of these Dockerfiles is that you know exactly what version of Ruby you're getting and it doesn't change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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