Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

The practical pattern is a multistage Docker image for Rails, plus a Compose application that runs the web container alongside PostgreSQL and stores database files in a named volume. In development, Compose can bind-mount your source tree for quick edits; in production, build an immutable image, remove the source mount, inject secrets at runtime, expose the required port, and set a restart policy.

Rails 7.1 and later generate a Dockerfile, .dockerignore, and bin/docker-entrypoint when you create a new application. Docker’s official Ruby on Rails guide documents both that generated setup and a Compose-based development workflow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What you are building

A containerized Rails deployment normally has two logical services:

  • web: the Rails application server, built from your Dockerfile.
  • db: PostgreSQL (or another database), with its data stored outside the disposable container filesystem.

Docker Compose describes those services in a YAML file. The file follows the Compose Specification, which defines how to declare a multi-container application, networks, volumes, environment variables, and startup settings.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Compose creates a private network for the project by default. The web container reaches PostgreSQL by the service name db, not by localhost. Port publishing is only needed for traffic entering from your host or an external load balancer; container-to-container traffic uses the service’s internal port.

Check the Rails application before writing containers

Match the Ruby version

Read .ruby-version and use the same Ruby major and minor version in the base image. A mismatch can change native-extension compilation, Bundler resolution, or the behavior of production gems. If the file says 3.3.4, for example, start from a Ruby 3.3 image that is compatible with your lockfile rather than choosing an unrelated version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Identify native and database dependencies

List the operating-system libraries required by your bundle and database adapter. PostgreSQL’s pg gem needs PostgreSQL client development headers while gems with native C extensions need a compiler and related build tools. Runtime images should contain only the shared libraries needed to execute the compiled gems, not the full compiler toolchain.

Confirm Rails’ container files

For an application generated with Rails 7.1 or newer, check whether these files already exist:

  • Dockerfile, normally a production-oriented multistage build.
  • .dockerignore, which keeps local artifacts such as Git data and temporary files out of the build context.
  • bin/docker-entrypoint, which performs the generated container startup preparation.

The generated Dockerfile is labeled by Docker as designed for production, not development. That is why a development Compose file usually adds a database service, a source-code mount, and a persistent volume.

Use a multistage Dockerfile

A multistage build separates compilation from execution. The build stage installs Bundler dependencies and precompiles assets. The runtime stage copies the resulting application and installed gems into a smaller image. Keeping the stages separate reduces attack surface and avoids shipping build tools that the running server does not need.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The following is a dependency-aware template. Replace the Ruby argument with the version required by your .ruby-version, adjust operating-system packages for your gems, and keep the generated entrypoint if Rails created one.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
ARG RUBY_VERSION=3.3
FROM ruby:${RUBY_VERSION}-slim AS build

WORKDIR /rails
ENV RAILS_ENV=production 
    BUNDLE_WITHOUT=development:test 
    BUNDLE_PATH=/usr/local/bundle

RUN apt-get update -qq && apt-get install --no-install-recommends -y 
    build-essential git pkg-config libpq-dev 
    && rm -rf /var/lib/apt/lists/*

COPY Gemfile Gemfile.lock ./
RUN bundle install

COPY . .
RUN SECRET_KEY_BASE_DUMMY=1 bin/rails assets:precompile

FROM ruby:${RUBY_VERSION}-slim AS runtime
WORKDIR /rails
ENV RAILS_ENV=production 
    BUNDLE_WITHOUT=development:test 
    BUNDLE_PATH=/usr/local/bundle

RUN apt-get update -qq && apt-get install --no-install-recommends -y 
    libpq5 
    && rm -rf /var/lib/apt/lists/*

COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

ENTRYPOINT /rails/bin/docker-entrypoint
EXPOSE 3000
CMD bin/rails server -b 0.0.0.0 -p 3000

The exact package names differ for MySQL, image-processing libraries, JavaScript runtimes, or other native dependencies. Install development packages only in build; install the corresponding runtime libraries in runtime. If your application does not precompile assets, remove that command rather than forcing a dummy secret into a build that does not need it.

Keep secrets out of the image

Do not copy config/master.key, production credentials, database passwords, or API tokens into the build context. Add them to .dockerignore where appropriate and pass them when the container starts. A secret baked into an image can remain in layer history even after the source line is removed.

Write a useful .dockerignore

At minimum, exclude the local Git directory, log files, temporary files, test artifacts, and any local environment file containing secrets. Do not exclude files needed by the build, such as Gemfile.lock, Rails source, or asset manifests.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a development compose.yaml

Compose service names become DNS names on the project network. In this example, Rails connects to PostgreSQL at host db, port 5432. The named volume keeps database files when the db container is recreated.

services:
  web:
    build:
      context: .
      args:
        RUBY_VERSION: 3.3
    command: bin/rails server -b 0.0.0.0 -p 3000
    ports:
      - '3000:3000'
    volumes:
      - .:/rails
    environment:
      RAILS_ENV: development
      DATABASE_URL: postgresql://rails:rails_password@db:5432/rails_development
    depends_on:
      - db

  db:
    image: postgres:16
    environment:
      POSTGRES_USER: rails
      POSTGRES_PASSWORD: rails_password
      POSTGRES_DB: rails_development
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:

The 3000:3000 mapping makes the app available at http://localhost:3000, the address used in Docker’s Rails example. Rails must listen on 0.0.0.0; binding only to 127.0.0.1 would make the server reachable inside the container but not through the published host port.

Align database.yml with Compose

Use either DATABASE_URL or explicit settings in config/database.yml, but make the host db rather than localhost. A typical development configuration reads the URL from the environment:

development:
  url: <%= ENV.fetch('DATABASE_URL') %>
  adapter: postgresql

Keep credentials out of committed YAML. For a team, place local values in an untracked environment file or use a secret mechanism supported by your deployment platform.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Bind mounts versus synchronized source

The .:/rails bind mount makes edits on the host visible immediately, which is convenient for development. It also hides the application files copied into the image at that path. Make sure the host directory contains the complete Rails checkout and that dependencies are available in the container’s bundle path. On systems where bind mounts are slow, use a file-synchronization feature or an image rebuild workflow instead.

Build and start the stack

  1. From the directory containing compose.yaml, build and run in the foreground with docker compose up --build. The build compiles gems and assets before Compose starts the services.
  2. For a background workflow, use docker compose up --build -d, then inspect status with docker compose ps.
  3. Open http://localhost:3000. Rails logs appear in the foreground terminal or can be followed with docker compose logs -f web.
  4. Supply the Rails credentials key at startup when the application needs encrypted credentials: RAILS_MASTER_KEY=<value> docker compose up --build. The angle-bracketed text represents your actual key; do not commit it to Compose.

When the database container is still initializing, the web process may start before PostgreSQL accepts connections. A restart or a second migration attempt may be necessary unless you add an explicit health check and startup handling. Compose’s basic depends_on ordering starts db first but does not, by itself, prove that the database is ready to accept SQL.

Run migrations and administrative commands

After PostgreSQL is available, run migrations inside the web container:

docker compose exec web bin/rails db:migrate

Other useful commands follow the same pattern:

  • docker compose exec web bin/rails db:prepare creates or updates the database where supported by your Rails version.
  • docker compose exec web bin/rails console opens a Rails console in the running container.
  • docker compose exec web bundle exec rake -T lists available Rake tasks.
  • docker compose run --rm web bin/rails db:setup runs a one-off task in a temporary web container.

Use exec for a running service so it shares the service’s environment and network. Use run --rm for an isolated task that should be removed after completion.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand persistence and teardown

Containers are replaceable; the named postgres_data volume is the durable part of the development database. Recreating the db service does not erase that volume. Treat docker compose down -v as destructive: the -v option removes project volumes and therefore deletes the local PostgreSQL data unless you have a backup.

Do not use a database volume as a substitute for backups. Production PostgreSQL needs scheduled backups, restore tests, monitoring, upgrades, and access controls in addition to Docker persistence.

Choose the database deliberately

SQLite is easy for a single-process prototype, but a containerized production setup should match the database behavior and operational model you will run in production. PostgreSQL and MySQL provide a client/server database service; each requires the matching adapter, client libraries, credentials, and persistent storage.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
Option Container arrangement When it fits Important trade-off
SQLite Database file in the web container or a mounted volume Small prototypes, tests, or applications intentionally designed for a single writer Less production parity when the eventual deployment uses a separate database server; file locking and concurrent writes require care
PostgreSQL Rails web service plus a PostgreSQL service and named data volume Rails applications that need a conventional production-grade relational database and strong local/production parity Requires a database service, credentials, migrations, backups, and PostgreSQL client libraries
MySQL Rails web service plus a MySQL service and its own data volume Teams standardized on MySQL-compatible infrastructure Requires the MySQL adapter and client development/runtime libraries; SQL behavior can differ from PostgreSQL

Changing engines later is a data migration project, not merely a Compose image change. Choose the engine that matches the production target and test migrations against that engine.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Separate development and production settings

Development optimizes for fast feedback; production optimizes for repeatability and controlled change. Docker’s production guidance recommends removing application-code volume bindings, changing ports and environment variables, and specifying a restart policy. The following differences are the ones that matter most:

Concern Development Compose Production Compose
Application files Optional host bind mount such as .:/rails No source-code bind mount; run the files copied into the built image
Rails environment RAILS_ENV=development, local debugging and reload behavior RAILS_ENV=production, compiled assets and production logging
Secrets Untracked local environment values Runtime secret injection or a secret file managed by the deployment system
Ports Usually host port 3000 to container port 3000 Expose the host port required by the proxy or platform; do not assume 3000 is externally appropriate
Restart behavior Manual restarts are usually acceptable Set a policy such as unless-stopped or the policy required by your orchestrator
Database Local named volume for disposable development data Managed or separately operated database with backups, monitoring, and controlled credentials

Build a production-oriented Compose file

You can keep one file and override values, or use a separate production file. A separate file makes it harder to accidentally ship a host source mount. This minimal example assumes the image has already been built or is pulled from your registry:

services:
  web:
    image: registry.example/rails-app:release-2026-10-15
    command: bin/rails server -b 0.0.0.0 -p 3000
    ports:
      - '8080:3000'
    environment:
      RAILS_ENV: production
      DATABASE_URL: ${DATABASE_URL}
      RAILS_MASTER_KEY: ${RAILS_MASTER_KEY}
    restart: unless-stopped

  db:
    image: postgres:16
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: unless-stopped

volumes:
  postgres_data:

The image tag is an example release identifier; use the immutable tag or digest policy required by your registry. Keep the production environment file outside source control, restrict its permissions, and ensure the deployment system does not print secret values in logs. If your platform supplies a managed database, remove the db service and point DATABASE_URL at that database instead.

Run production migrations deliberately

Do not make every web container run migrations concurrently at startup unless your release process explicitly handles locking and failure recovery. A safer pattern is to deploy the image, run docker compose run --rm web bin/rails db:migrate as a release task, verify success, and then start or roll the web service. Test backward-compatible migrations when old and new application versions overlap during a rollout.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put TLS and process supervision in the right layer

Rails can serve HTTP inside the container while a reverse proxy, load balancer, or hosting platform terminates TLS and forwards traffic to the published port. Compose does not automatically provide certificates, internet-facing firewall rules, health monitoring, horizontal scaling, or zero-downtime deployment. Add those capabilities separately or use a managed service that supplies them.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Single Compose file or an override?

A single file is convenient for a small project, but environment-specific settings can become difficult to audit. An override keeps the common service definition in compose.yaml and puts production changes in a second file:

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
  • Base file: build context, common environment names, internal ports, and the development database definition.
  • Production override: immutable image, no source bind mount, production environment, external secrets, published port, and restart policy.

Invoke both explicitly, for example docker compose -f compose.yaml -f compose.production.yaml up -d. Whichever layout you choose, inspect the resolved configuration with docker compose config before deploying; this catches accidental mounts, incorrect interpolation, and missing required variables.

Common failures and fixes

“Connection refused” from Rails

Check that the database service is running with docker compose ps, that Rails uses host db, and that the database name, user, and password match. If the log shows a startup race, wait for PostgreSQL readiness and rerun the migration or add a health check plus a readiness-aware startup strategy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“Could not find gem” or native extension errors

Verify that the image Ruby version matches .ruby-version and that Gemfile.lock is copied before bundle install. Add the required compiler and development headers to the build stage, then rebuild with docker compose build --no-cache web when a stale layer is masking a dependency change.

The browser cannot reach Rails

Confirm that the server command binds to 0.0.0.0, the container listens on port 3000, and Compose publishes the expected host port. Inspect docker compose logs web for boot failures. A server bound to localhost inside the container is not reachable through the host mapping.

Changes on the host are ignored

In development, verify the bind mount path and remember that it replaces the image’s /rails directory. Rebuild after changing the Dockerfile or Gemfile. If the host filesystem does not provide reliable file events, use polling or a synchronization workflow supported by your development environment.

Assets or credentials fail only in production

Ensure the build stage runs the required asset task, that runtime assets were copied into the final stage, and that RAILS_MASTER_KEY is present at runtime. A dummy build secret can allow precompilation, but it cannot decrypt production credentials; the real key must remain a runtime secret.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The database disappeared

Check whether the service was started with a named volume and whether someone ran docker compose down -v. Restore from a backup if the volume was removed. For production, document backup retention and test restoration instead of relying on a local Docker volume.

Security and reliability checklist

  • Pin Ruby, database, and other base-image versions that you test; update them through a controlled rebuild.
  • Keep Gemfile.lock under version control and rebuild when dependencies change.
  • Exclude credentials from the build context and inject RAILS_MASTER_KEY and database secrets only at runtime.
  • Run the smallest practical runtime image and do not leave compilers or package indexes in it.
  • Use a non-development Rails environment in production and remove source-code mounts.
  • Persist database data in a managed volume or managed database, and maintain tested backups.
  • Set restart behavior, collect container logs, and monitor both web and database health.
  • Run migrations as a controlled release step and verify the result before directing traffic to a new version.
  • Place TLS termination, firewall rules, and public exposure behind an appropriately managed proxy or platform.

When local Compose is enough

Compose is an excellent local development environment and can run a small deployment on a host you administer. You remain responsible for operating-system updates, image storage, TLS, backups, monitoring, secret distribution, database upgrades, capacity planning, and recovery. A managed service that accepts container or Compose definitions can reduce that operational burden, but you still need to verify its networking model, persistent storage, secret handling, logs, health checks, migration workflow, and scaling behavior before moving a production Rails app.

The portable boundary is the image: build and test the same Rails image locally and in the target environment, while allowing each environment to supply its own database URL, secrets, ports, and restart or scaling policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.