▸text34 lines · 829 chars
FROM ruby:alpine3.23
# Install system dependencies and build tools
RUN apk update \
&& apk add --no-cache build-base libxml2-dev libxslt-dev libffi-dev zlib-dev \
&& rm -rf /var/cache/apk/*
# Install essential Ruby gems
RUN gem install bundler && gem install rack
# Create a non-root user for running the application
RUN addgroup -S app && adduser -S -G app app
# Set work directory for the application
WORKDIR /app
# Copy source code
COPY . .
# Ensure proper permissions
RUN chown -R app:app /app
# Install Ruby dependencies (if a Gemfile is present). This must run as root.
RUN if [ -f Gemfile ]; then bundle install; fi
# Switch to non-root user for running the app
USER app
# Expose the application port
EXPOSE 9292
# Command to run the Rack-based app
CMD ["rackup", "config.ru", "-o", "0.0.0.0", "-p", "9292"]