Skip to content

Deploying Your App Locally

Overview

  • Running Docker compose

The first step is both obvious and often overlooked: deploy your application first locally before trying to deploy it on another server.

Consider a simple Rails application. For example, this is from the Depot application in Agile Web Development with Rails:

$ rails new depot --css tailwind

$ cd depot

$ bin/rails generate scaffold Product \
  title:string description:text image:attachment price:decimal

$ bin/rails active_storage:install

$ bin/rails db:migrate

Now create a file named compose.yml and place within it the following:

services:
  web:
    build: .
    volumes:
      - ./log:/rails/log
      - ./storage:/rails/storage
    ports:
      - "3000:3000"
    secrets:
      - source: master_key
        target: /rails/config/master.key

secrets:
  master_key:
    file: ./config/master.key

Install Docker and then run:

$ docker compose up

After about a minute, your app will be running in production on your personal laptop or desktop. You can access it via http://localhost:3000/products. Your log and storage will be read and written to by the container, but nothing else on your machine will be accessible.

You can even run commands in your container:

$ docker compose exec web bin/rails console

The importance of this first step can't be overstated. Your first deploy with a real application will likely fail. In a not insignificant number of cases, one of the contributing causes is that this is the first time your application is run in production and your Dockerfile is not set up correctly, your seed data is incomplete, or some secret needs to be set.

Rails will provide you with a Dockerfile when you create your application, but your application may have changed since then.

Note

It's even possible that the Rails-provided Dockerfile never worked in the first place. For example, starting on February 14th, 2025, Ruby Docker images no longer included the libyaml-dev module. This broke the Rails-provided Dockerfile. The fix was straightforward and merged into Rails source on January 14th. Unfortunately, this fix was not included in a release until Rails 8.0.2 on March 12th, 2025. So for nearly a month, the Dockerfile produced by the latest released Rails version did not work with the latest released Ruby version. At the time of this writing, new projects created by previous versions of Rails still produce Dockerfiles that don't work with the latest version of Ruby.

Fly.io provides a dockerfile-rails generator that can examine your code and provide you with a new Dockerfile that matches your application.

Other frameworks may not provide you with a Dockerfile to get started. Fly.io provides Dockerfile generators for Django, Laravel, and Node. You do not need to be using Fly.io to use these generators.

This compose.yml file is a good starting point for most applications. Applications that have external dependencies may require more setup. See examples for PostgreSQL and Redis.

Visit the Docker Documentation for more information on docker compose.