FROM ruby:3.2-slim # Create app directory WORKDIR /app # Install Rack (minimal Rack web server) for running the static Rack app RUN gem update --system && gem install rack # Copy project files into the container COPY . . # Expose port Rack uses by default EXPOSE 9292 # Run the Rack app on container start CMD ["rackup", "-p", "9292", "-o", "0.0.0.0"]
node_modules .git .DS_Store .bundle .env log/ tmp/
Concerns: Assumes a Rack config (config.ru) exists at /app; if missing, rackup may fail when the container starts., Does not install app-specific dependencies (e.g., via Bundler); if the project relies on additional gems, the app may not run without extra build steps. Smoke [PASS]: ruby -v Smoke [FAIL]: rackup -V Output: sh: 1: rackup: not found Smoke [PASS]: test -f /app/config.ru || test -f /app.ru
FROM ruby:3.2-slim
# Create app directory
WORKDIR /app
# Install Rack (for running the Rack app) and standard tooling
RUN gem update --system && gem install rack
# Copy project files into the container
COPY . .
# Expose port Rack uses by default
EXPOSE 9292
# Run the Rack app using Ruby directly (avoid rackup binary issues)
CMD ["ruby", "-e", "require 'webrick'; require 'rack'; app = Rack::Builder.parse_file('config.ru'); Rack::Handler::WEBrick.run(app, :Port => 9292, :Bind => '0.0.0.0')"]
Concerns: No Gemfile/Bundler step: the image installs rack globally instead of using the project's dependency management. If the app relies on other gems, they may be missing or version-conflict with the host/system Ruby., WEBrick Bind option: using :Bind => '0.0.0.0' may not be portable across all Ruby/WEBrick versions; some setups expect :Host or :BindAddress., COPY . . may leak unwanted files: ensure a proper .dockerignore to avoid copying sensitive or large files (e.g., tests, secrets, local configs).
Smoke [PASS]: test -f config.ru
Smoke [FAIL]: ruby -e "begin; require 'rack'; app = Rack::Builder.parse_file('config.ru'); puts 'rack app loaded'; rescue => e; puts e.message; exit 1 end
Output: sh: 1: Syntax error: Unterminated quoted stringFROM ruby:3.2-slim WORKDIR /app # Update package index and install minimal deps RUN apt-get update -qq -y \ && rm -rf /var/lib/apt/lists/* # Install the rack gem so we can run the Rack app RUN gem update --system && gem install rack -N # Copy project files COPY . . # Expose the port the rack app will listen on EXPOSE 9292 # Start the Rack-based application CMD ["ruby", "start_server.rb"]
require 'rack'
app = Rack::Builder.parse_file('config.ru')
Rack::Handler::WEBrick.run(app, Port: 9292, BindAddress: '0.0.0.0')
Concerns: Only the rack gem is explicitly installed; if the project uses Gemfile/Bundler for dependencies, gems may be missing at runtime., No non-root user is configured; consider security improvements for running a web service., COPY . . may bring in development files; consider using a .dockerignore to reduce image size and surface area.
Smoke [FAIL]: bash -lc 'ruby start_server.rb & PID=$!; sleep 1.5; if curl -sS -o /dev/null -w %{http_code} http://localhost:9292/ | grep -q 200; then echo OK; else echo FAIL; fi; kill $PID
Output: sh: 1: Syntax error: Unterminated quoted stringFROM ruby:3.2-slim
WORKDIR /app
# Install minimal system deps
RUN apt-get update -qq -y \
&& rm -rf /var/lib/apt/lists/*
# Install rack (for running the Rack app)
RUN gem update --system && gem install rack -N
# Copy project files
COPY . .
# Expose port for the Rack app
EXPOSE 9292
# Start the Rack-based application using a Ruby one-liner to avoid rackup binary issues
CMD ["ruby", "-e", "require 'rack'; app = Rack::Builder.parse_file('config.ru'); require 'webrick'; Rack::Handler::WEBrick.run(app, :Port => 9292, :BindAddress => '0.0.0.0')"]
Concerns: No explicit build/dependency installation step (e.g., bundle install) from Gemfile; app dependencies may be missing and the app may fail to start., COPY . . copies source, but there is no build step to compile assets or install runtime dependencies beyond a single Rack gem; this may not truly 'build from source'., Starting Rack app via Rack::Builder.parse_file('config.ru') without calling .to_app() can be brittle across Rack versions or configurations., Apt-get is run without installing any packages, making that step effectively a no-op and potentially confusing.FROM ruby:3.2-slim # Set working directory WORKDIR /app # Install minimal system dependencies RUN apt-get update -qq -y \ && rm -rf /var/lib/apt/lists/* # Install rack gem (required to run the Rack app) RUN gem update --system && gem install rack -N # Copy the project files into the image COPY . . # Expose the port the app will run on EXPOSE 9292 # Start the Rack-based application using a small Ruby script (start_server.rb) CMD ["ruby", "start_server.rb"]
require 'rack'
app = Rack::Builder.parse_file('config.ru').to_app
require 'webrick'
Rack::Handler::WEBrick.run(app, :Port => 9292, :BindAddress => '0.0.0.0')
Concerns: If the project uses Bundler (Gemfile), there is no bundle install step in the Dockerfile, so app dependencies may be missing at runtime., COPY . . may bring in unnecessary files (e.g., tests, docs). Consider adding a .dockerignore to keep the image lean. Smoke [PASS]: test -f /app/start_server.rb Smoke [FAIL]: ruby -e 'begin; require "rack"; puts "rack loaded"; rescue LoadError; exit 1; end Output: sh: 1: Syntax error: Unterminated quoted string
Concerns: No bundler install step; app dependencies specified in Gemfile may not be installed, relying on rack alone., COPY . . copies entire repo; potential inclusion of unnecessary files or secrets.
Smoke [PASS]: test -f /app/start_server.rb
Smoke [FAIL]: ruby /app/start_server.rb & sleep 1; ruby -e 'require "net/http"; res = Net::HTTP.get_response("127.0.0.1", 9292, "/"); puts res.code
Output: sh: 1: Syntax error: Unterminated quoted stringFROM ruby:3.2-slim # Set workdir WORKDIR /app # Install minimal system dependencies RUN apt-get update -qq -y \ && rm -rf /var/lib/apt/lists/* # Install rack (provides rackup) for running the Rack app RUN gem update --system && gem install rack -N # Copy project files COPY . . # Expose the port the Rack app will listen on EXPOSE 9292 # Start the Rack-based application on container startup CMD ["rackup", "-p", "9292", "-o", "0.0.0.0"]
Concerns: No build step or bundler/install of app dependencies: the image only installs Rack globally and copies the source, but there is no bundle install or compilation of the app from its Gemfile. This does not satisfy 'builds the application from source'., Potential missing dependencies: if the app relies on Gemfile dependencies, they won't be installed automatically, leading to runtime failures., No guarantee of Rack config presence: rackup expects a config.ru (or similar) in the working directory; COPY . . may copy files that don't provide a Rack config, causing rackup to fail at startup., Minor inefficiency: apt-get update is performed but no packages are installed; this is effectively a no-op and may be unnecessary.
FROM ruby:3.2-slim # Set working directory WORKDIR /app # Install minimal system dependencies (if any in future) RUN apt-get update -qq -y \ && rm -rf /var/lib/apt/lists/* # Install rack (to run the Rack-based app) RUN gem update --system && gem install rack -N # Copy the project files COPY . . # Expose the port the app will listen on EXPOSE 9292 # Start the Rack-based application CMD ["ruby", "start_server.rb"]
require 'rack'
app = Rack::Builder.parse_file('config.ru').to_app
require 'webrick'
Rack::Handler::WEBrick.run(app, :Port => 9292, :BindAddress => '0.0.0.0')
Concerns: App may require additional gems via Bundler (Gemfile); Dockerfile only installs rack and does not run bundle install, which could cause runtime failures if dependencies are missing., No non-root user context; running as root may be a security concern. Smoke [FAIL]: sh -lc 'ruby start_server.rb & PID=$!; sleep 2; if curl -sS http://127.0.0.1:9292/ >/dev/null; then echo OK; else echo FAIL; fi; kill $PID Output: sh: 1: Syntax error: Unterminated quoted string
FROM ruby:3.1-slim # Install system dependencies required to build native extensions and run the app RUN apt-get update -qq && apt-get install -y --no-install-recommends \ build-essential \ libssl-dev \ git \ ca-certificates \ tzdata \ && rm -rf /var/lib/apt/lists/* # Ensure Bundler is available RUN gem install bundler # Create a non-root user to run the application RUN useradd -m appuser WORKDIR /app # Copy application code COPY . . # Copy startup script into image (to be executed as root, then switched to non-root user) COPY start.sh /usr/local/bin/start.sh RUN chmod +x /usr/local/bin/start.sh # Ensure the app directory and startup script are owned by the non-root user RUN chown -R appuser:appuser /app /usr/local/bin/start.sh USER appuser EXPOSE 9292 # Start the server using the startup script CMD ["/usr/local/bin/start.sh"]
#!/bin/sh set -e # Must have a Rack-compatible app (config.ru) if [ -f config.ru ]; then echo "Starting Rack server on port 9292" exec rackup -p 9292 -o 0.0.0.0 else echo "config.ru not found; cannot start server" exit 1 fi
Concerns: No explicit build/install step for application dependencies (e.g., bundle install). The image copies the application code but does not install gems, which means the app may fail to start unless the start.sh script performs installation at runtime., Although a startup script is provided, the Dockerfile does not verify or run any build steps for native extensions or gems, reducing predictability of the build., Potential reliance on start.sh at runtime without ensuring dependencies are pre-installed could lead to failures in production if start.sh expects gems to be present.
FROM ruby:3.1-slim # Install system dependencies required to build native extensions and run the app RUN apt-get update -qq && apt-get install -y --no-install-recommends \ build-essential \ libssl-dev \ git \ ca-certificates \ tzdata \ && rm -rf /var/lib/apt/lists/* # Ensure Bundler is available RUN gem install bundler # Create a non-root user to run the application RUN useradd -m appuser WORKDIR /app # Copy Gemfiles first to leverage Docker layer caching COPY Gemfile* ./ # Install dependencies if a Gemfile is present RUN if [ -f Gemfile ]; then bundle install --without development test; else echo "No Gemfile found, skipping bundle install"; fi # Copy the rest of the application code COPY . . # Ensure the app directory and startup script are owned by the non-root user RUN chown -R appuser:appuser /app # Copy startup script into image (to be executed as root, then switched to non-root user) COPY start.sh /usr/local/bin/start.sh RUN chmod +x /usr/local/bin/start.sh USER appuser EXPOSE 9292 # Start the server using the startup script CMD ["/usr/local/bin/start.sh"]
FROM ruby:3.1-slim # Install system dependencies required to build native extensions and run the app RUN apt-get update -qq && apt-get install -y --no-install-recommends \ build-essential \ libssl-dev \ git \ ca-certificates \ tzdata \ && rm -rf /var/lib/apt/lists/* # Ensure Bundler is available RUN gem install bundler # Create a non-root user to run the application RUN useradd -m appuser WORKDIR /app # Copy Gemfiles first to leverage Docker layer caching COPY Gemfile* ./ # Install dependencies if a Gemfile is present; otherwise install rack for a pure Rack app RUN if [ -f Gemfile ]; then bundle install --without development test; else gem install rack; fi # Copy the rest of the application code COPY . . # Ensure the app directory and startup script are owned by the non-root user RUN chown -R appuser:appuser /app # Copy startup script into image (to be executed as root, then switched to non-root user) COPY start.sh /usr/local/bin/start.sh RUN chmod +x /usr/local/bin/start.sh USER appuser EXPOSE 9292 # Start the server using the startup script CMD ["/usr/local/bin/start.sh"]
Smoke [PASS]: test -x /usr/local/bin/start.sh Smoke [FAIL]: sh -c '/usr/local/bin/start.sh > /tmp/server.log 2>&1 & sleep 2; curl -sSf http://localhost:9292/ >/dev/null Output: sh: 1: Syntax error: Unterminated quoted string
#!/bin/sh set -e # Must have a Rack-compatible app (config.ru) if [ -f config.ru ]; then echo "Starting Rack server on port 9292" exec rackup -p 9292 -o 0.0.0.0 else echo "config.ru not found; cannot start server" exit 1 fi
#!/bin/sh set -e # Must have a Rack-compatible app (config.ru) if [ -f config.ru ]; then echo Starting Rack server on port 9292 exec rackup -p 9292 -o 0.0.0.0 else echo config.ru not found; cannot start server exit 1 fi
Concerns: start.sh must exist in the build context; if absent, the build will fail when COPY start.sh is executed, If the app binds to a different port or to a non-loopback interface, the smoke tests targeting 127.0.0.1:9292 may fail, Dockerfile lacks a HEALTHCHECK; adding one could improve automated health validation beyond the smoke tests
Smoke [FAIL]: /usr/local/bin/start.sh & sleep 2; ruby -rnet/http -e "puts Net::HTTP.get_response(URI('http://127.0.0.1:9292/')).code
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [FAIL]: /usr/local/bin/start.sh & sleep 2; ruby -rnet/http -e 'r = Net::HTTP.get_response(URI("http://127.0.0.1:9292/")); puts r.code; puts r.body[0,100]
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [PASS]: ps aux | grep -E 'ruby|rack' | grep -v grep | head -n 1#!/bin/sh set -e if [ -f config.ru ]; then echo "Starting Rack server on port 9292" exec rackup -p 9292 -o 0.0.0.0 else echo "config.ru not found; cannot start server" exit 1 fi
Concerns: COPY Gemfile* ./: globbing will fail if no Gemfile in build context; ensure a Gemfile exists in the repository, No explicit HEALTHCHECK; consider adding a simple health check to verify runtime readiness Smoke [PASS]: test -f /usr/local/bin/start.sh Smoke [FAIL]: test -f /app/Gemfile Output: Smoke [PASS]: ruby -v
FROM ruby:3.1-slim # Install system dependencies required to build native extensions and run the app RUN apt-get update -qq && apt-get install -y --no-install-recommends \ build-essential \ libssl-dev \ git \ ca-certificates \ tzdata \ && rm -rf /var/lib/apt/lists/* # Ensure Bundler is available RUN gem install bundler # Create a non-root user to run the application RUN useradd -m appuser WORKDIR /app # Copy the complete application code COPY . . # Install dependencies if a Gemfile is present; otherwise install rack for a pure Rack app RUN if [ -f Gemfile ]; then bundle install --without development test; else gem install rack; fi # Ensure the app directory is owned by the non-root user RUN chown -R appuser:appuser /app # Copy startup script into image (to be executed as root, then switched to non-root user) COPY start.sh /usr/local/bin/start.sh RUN chmod +x /usr/local/bin/start.sh USER appuser EXPOSE 9292 # Start the server using the startup script CMD ["/usr/local/bin/start.sh"]
Concerns: The Dockerfile copies start.sh; ensure it exists in the build context, otherwise the image build will fail., No HEALTHCHECK defined; consider adding one to verify runtime availability. Smoke [PASS]: test -x /usr/local/bin/start.sh Smoke [PASS]: ruby -v Smoke [PASS]: bundle -v