01 / 04
Pick a base image
Use the slim official image and add only what you need. Alpine works but musl vs glibc bugs will find you eventually — start with Debian slim and only optimize if the size matters.
DockerfileFROM ruby:3.3-slim AS build RUN apt-get update -qq && apt-get install -y build-essential git WORKDIR /app COPY Gemfile Gemfile.lock ./ RUN bundle config set --local deployment 'true' \ && bundle config set --local without 'development test' \ && bundle install --jobs 4 FROM ruby:3.3-slim WORKDIR /app COPY --from=build /usr/local/bundle /usr/local/bundle COPY . . ENV RUBY_YJIT_ENABLE=1 MALLOC_ARENA_MAX=2 CMD ["ruby", "bin/worker"]