These guides are still a work in progress and may change as we improve the documentation. Please check back later for updates.
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.
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
Look in the examples
directory of the LocoMotion
repository
for these basic configuration files:
docker-compose.yml
- Defines your application servicesDockerfile
- Instructions for building your app containerdev/Dockerfile
- Development environment containerentrypoint.sh
- Script that runs when containers startMakefile
- Shortcuts for common commandsCopy 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
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
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
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
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.
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.
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"]
You now have a complete Docker development environment for your Rails application! This setup provides:
Create virtual credit / debit cards to keep your real info safe.
Get $5 when you sign up — free to start!
Everything you need to grow your business with confidence!
CRM, Lead Generation, Project Management, Contracts, Online Payments, and more!
The ads above are affiliate links to products I regularly use and highly
recommend.
I may receive a commission if you decide to purchase.