1

Recently we have moved the rails application to docker for development. I am using MacBook Pro (M1, 2020), OS Version: 12.0.1. Now the application works, but that is extremely slow on local machine, is there anything we can do here to improve the performance, or are we doing something incorrectly?

Rails Version

rails (5.2.8.1)

Dockerfile

FROM ruby:2.5.9

ENV INSTALL_PATH /opt/app
RUN mkdir -p $INSTALL_PATH

RUN apt-get update && apt-get install -y \
#   curl \
#   chromium \
  build-essential \
  libpq-dev \
  curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
  apt-get update && apt-get install -y nodejs

RUN gem install bundler -v 2.3.26
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock

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

WORKDIR /opt/app/core-project

VOLUME ["$INSTALL_PATH/public"]

# For Rails
EXPOSE 4000

config/database.yml

development:
  adapter: postgresql
  url: postgresql://postgres@host.docker.internal:5432/coredb?encoding=utf8&pool=5&timeout=5000

docker-compose.yml

version: "3.7"

services:
  redis:
    image: redis:6.2
  rails-server:
    build:
      context: .
      args:
        USER_ID: "${USER_ID:-1000}"
        GROUP_ID: "${GROUP_ID:-1000}"
    command: ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
    depends_on:
      - redis
    volumes:
      - type: bind
        source: ./
        target: /opt/app/core-project
    ports:
      - '4000:3000'
    env_file:
      - .env

  sidekiq:
    build:
      context: .
      args:
        USER_ID: "${USER_ID:-1000}"
        GROUP_ID: "${GROUP_ID:-1000}"
    command: ["bundle", "exec", "sidekiq"]
    depends_on:
      - redis
    volumes:
      - type: bind
        source: ./
        target: /opt/app/core-project
    env_file:
      - .env

application.rb

# Added to resolve the segmentation issue when running the application in Docker.
config.assets.configure do |env|
  env.export_concurrent = false
end
Developer
  • 561
  • 7
  • 29
  • 1
    That sounds like you're running into [Docker in MacOs is very slow](https://stackoverflow.com/questions/55951014/docker-in-macos-is-very-slow). For a development environment, I might `brew install rbenv` to get a local Ruby, and skip Docker; for pre-deployment testing, delete the `volumes:` blocks. – David Maze Jun 24 '23 at 21:35

1 Answers1

0

Docker is not a good solution to dev. use RVM to avoid ruby version mismatching .

\curl -sSL https://get.rvm.io  | bash

and after you source the right things in the post install logs you can specify the version you want to have :

rvm install x.X.X

Where x.X.X is the ruby version you want clone or copy pour project , and run bundle install . google your error of installs (if you have some) IT should be now BLAZIN'FAST

plombix
  • 396
  • 3
  • 13