Search code examples
ruby-on-railsdockerdockerfilebundlegemfile

Docker with bundle install doesn't behave same on my VPS and Mac


My Dockerfile

FROM ruby:2.6.3-alpine

ENV BUNDLER_VERSION=2.2.6

RUN apk add --update --no-cache \
      binutils-gold \
      build-base \
      curl \
      file \
      g++ \
      gcc \
      git \
      less \
      libstdc++ \
      libffi-dev \
      libc-dev \
      linux-headers \
      libxml2-dev \
      libxslt-dev \
      libgcrypt-dev \
      make \
      netcat-openbsd \
      nodejs \
      openssl \
      pkgconfig \
      postgresql-dev \
      python \
      tzdata \
      yarn

RUN gem install bundler -v 2.2.6

WORKDIR /app

COPY Gemfile Gemfile.lock ./

RUN bundle config build.nokogiri --use-system-libraries

RUN bundle check || bundle install

COPY package.json yarn.lock ./

RUN yarn install --check-files

COPY . ./

ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]

docker-compose.yml

version: '3.4'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - database
      - redis
    ports:
      - "3000:3000"
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    env_file: .env
    environment:
      RAILS_ENV: development

  database:
    image: postgres:12.1
    volumes:
      - db_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - "5432:5432"

  redis:
    image: redis:5.0.7

  sidekiq:
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - app
      - database
      - redis
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    env_file: .env
    environment:
      RAILS_ENV: development
    entrypoint: ./entrypoints/sidekiq-entrypoint.sh

volumes:
  gem_cache:
  db_data:
  node_modules:

Things working fine on my Mac after building enter image description here

But on my VPS, it doesn't work as expected enter image description here

They were based on the exact same one Dockerfile and docker-compose.yml.

I know that I can push my working-fine image to the docker hub and just use it, but I still want to know where goes wrong? They are working in the Alpine environment, shouldn't be different.

I've dug the error info, and then I've tried some workarounds but got into the same bundle error when meeting sassc.

This is the error output for sassc, did try the different versions still didn't work. enter image description here

But in the end, they all give me "Failed to build gem native extension."

What is the problem here? Why does it work fine in my Mac but my VPS(Ubuntu)? I'm getting stuck here


Solution

  • Mem was not quite enough for me to compile. Problem solved.

    There is only 1g1c on my VPS, and I'm running an Nginx and sidekiq. The mem is only about 600m in usual cases. Simply mem wasn't quite enough to compile and build.