Work in Progress

These guides are still a work in progress and may change as we improve the documentation. Please check back later for updates.

Docker Development Environment

We recommend using Docker to get your project setup from the beginning. This ensures that you have a stable development environment, no matter what OS or system you're using to develop.

It also allows you to troubleshoot and debug the application since the development container is small and simple with very few dependencies.

1. Initial Setup

First, you'll need to install Docker. You can download it from Docker's website.

Once installed, create a new directory for your project:

mkdir -p ~/Development/mycompany/myproject
cd ~/Development/mycompany/myproject

2. Configuration Files

Look in the examples directory of the LocoMotion repository for these basic configuration files:

  • docker-compose.yml - Defines your application services
  • Dockerfile - Instructions for building your app container
  • dev/Dockerfile - Development environment container
  • entrypoint.sh - Script that runs when containers start
  • Makefile - Shortcuts for common commands

Copy these files into your project directory. Your directory structure should look like this:

~/Development
└── mycompany
    └── myproject
        ├── Dockerfile
        ├── Makefile
        ├── dev
        │   └── Dockerfile
        ├── docker-compose.yml
        └── entrypoint.sh

3. Starting the Development Environment

With these files in place, you can now start your development environment:

make dev

This command will build and run all the necessary containers. Once they have started, open a shell in your development container with:

make dev-shell

4. Creating a Rails Application

Once inside the development container, you can create a new Rails application:

cd /home/app && rails new . --skip --database=postgresql --javascript=esbuild --css=tailwind

If you run into trouble with the Rails command, you can reset the files and try again by running the following rm command:

rm -rf .dockerignore .git .gitattributes .gitignore .node-version .ruby-version Gemfile README.md Rakefile app bin config config.ru

5. Database Configuration

After creating your Rails application, update the database configuration in config/database.yml:

# Under the default section in config/database.yml
host: db
username: postgres
password: password

6. Running Your Application

Now you can uncomment the app section in your docker-compose.yml file and start your application:

make app

After the application builds and starts, you should see output indicating that Rails is running. You can now visit http://localhost:3000 in your web browser to see your application.

Note

Once the container is built, you can run make app-quick to simply start the containers. This is much faster than running the full build every time.

7. Building JavaScript and CSS

To ensure JavaScript and CSS assets are properly bundled, update your Procfile.dev to bind to all interfaces:

web: env RUBY_DEBUG_OPEN=true bin/rails server -b 0.0.0.0

Also update your Dockerfile to use Foreman for starting the application:

# Change this line:
CMD ["rails", "server", "-b", "0.0.0.0"]

# To this:
CMD ["./bin/dev"]

Success!

You now have a complete Docker development environment for your Rails application! This setup provides:

  • Consistent development environment across any OS or system
  • Simple debugging and troubleshooting
  • Easy onboarding for new team members
  • Isolation from your host system's dependencies
Made with by Profoundry .
Copyright © 2023-2025 Profoundry LLC.
All rights reserved.