drun is a simple Docker container management tool for Ruby on Rails development. It provides a streamlined workflow for managing Rails applications in containers, with built-in support for PostgreSQL, Redis, and other essential services.
-
Install drun in an empty directory:
curl -o drun.sh https://raw.githubusercontent.com/Rynaro/drun/main/drun.sh curl -o docker-compose.yml https://raw.githubusercontent.com/Rynaro/drun/main/docker-compose.yml curl -o Dockerfile https://raw.githubusercontent.com/Rynaro/drun/main/Dockerfile curl -o .env.example https://raw.githubusercontent.com/Rynaro/drun/main/.env.example chmod +x drun.sh
-
Get suggested commands for new Rails projects:
./drun.sh suggested
-
Create a new Rails application (recommended):
./drun.sh rails new . --skip-docker --database=postgresql -
Start your development environment:
./drun.sh rails db:create ./drun.sh serve
-
Visit http://localhost:3000 in your browser
-
Copy drun files to your project root:
curl -o drun.sh https://raw.githubusercontent.com/Rynaro/drun/main/drun.sh curl -o docker-compose.yml https://raw.githubusercontent.com/Rynaro/drun/main/docker-compose.yml curl -o Dockerfile https://raw.githubusercontent.com/Rynaro/drun/main/Dockerfile curl -o .env.example https://raw.githubusercontent.com/Rynaro/drun/main/.env.example chmod +x drun.sh
-
Configure your environment (optional):
cp .env.example .env # Edit .env to customize database, ports, etc. -
Start your development environment:
./drun.sh serve
| Command | Description |
|---|---|
./drun.sh suggested |
Show suggested commands for new Rails projects |
./drun.sh help |
Show complete help with all available commands |
| Command | Description |
|---|---|
./drun.sh build |
Build containers |
./drun.sh up or ./drun.sh serve |
Start containers (foreground) |
./drun.sh down |
Stop containers |
./drun.sh restart |
Restart containers |
./drun.sh ps or ./drun.sh status |
Show container status |
./drun.sh logs [service] |
View logs (default: rails) |
| Command | Description |
|---|---|
./drun.sh shell or ./drun.sh bash |
Open bash shell in Rails container |
./drun.sh console |
Open Rails console |
./drun.sh rails <cmd> |
Run any Rails command |
./drun.sh rake <task> |
Run any Rake task |
./drun.sh bundle <cmd> |
Run any Bundler command |
./drun.sh test [args] |
Run Rails tests |
| Command | Description |
|---|---|
./drun.sh clean |
Clean project containers, volumes, and networks |
./drun.sh clean-all |
Clean all project resources including images |
| Command | Description |
|---|---|
./drun.sh thanks |
Show appreciation message |
./drun.sh <custom> |
Run custom commands directly in Rails container |
# 1. Set up drun in empty directory
curl -o drun.sh https://raw.githubusercontent.com/Rynaro/drun/main/drun.sh && chmod +x drun.sh
# 2. Get the suggested commands
./drun.sh suggested
# 3. Create Rails app (preserves drun Docker setup)
./drun.sh rails new . --skip-docker --database=postgresql
# 4. Set up database and start server
./drun.sh rails db:create
./drun.sh rails db:migrate
./drun.sh serve# 1. Add drun to your project
curl -o drun.sh https://raw.githubusercontent.com/Rynaro/drun/main/drun.sh
curl -o docker-compose.yml https://raw.githubusercontent.com/Rynaro/drun/main/docker-compose.yml
curl -o Dockerfile https://raw.githubusercontent.com/Rynaro/drun/main/Dockerfile
chmod +x drun.sh
# 2. Start development environment
./drun.sh serve# Start your work session
./drun.sh serve
# Generate models, controllers, etc.
./drun.sh rails generate model User name:string email:string
./drun.sh rails generate controller Users
# Run database migrations
./drun.sh rails db:migrate
# Run tests
./drun.sh test
./drun.sh rails test:system
# Debug in Rails console
./drun.sh console
# Install new gems
./drun.sh bundle add devise
./drun.sh bundle install
# Check routes
./drun.sh rake routes
# Clean up when done
./drun.sh downCreate a .env file to customize your setup:
# Copy the example file
cp .env.example .envKey configuration options:
PROJECT_NAME: Used for container naming (defaults to directory name)PORT: Rails server port (default: 3000)POSTGRES_DB: Database namePOSTGRES_USER: Database usernamePOSTGRES_PASSWORD: Database passwordREDIS_URL: Redis connection string
If you need to customize the Docker setup:
- Modify the Dockerfile for additional system packages
- Update docker-compose.yml for service configuration
- Rebuild containers with
./drun.sh build
drun provides a complete containerized development environment with:
- Ruby 3.4 (Alpine Linux for minimal footprint)
- Rails (globally installed and ready to use)
- PostgreSQL 17.5 with SCRAM-SHA-256 authentication
- Redis 8 for caching and background jobs
- Node.js & Yarn for asset compilation
- Multi-stage Docker builds for optimized images
- Non-root user (
drunner) for security - Persistent volumes for data, gems, and node_modules
- Health checks for all services
- Project-specific resource labeling
- Bundle path optimization for gem caching
- Hot reloading with volume mounts
- Custom command support for any Rails workflow
- Clean resource management with project isolation
drun follows security best practices:
- Non-root user execution (
drunneruser with UID 1000) - Minimal Alpine Linux base for reduced attack surface
- Multi-stage builds to exclude build dependencies from final image
- Proper file permissions for application and bundle directories
- PostgreSQL SCRAM-SHA-256 authentication
- Isolated database volumes with proper permissions
- Environment variable configuration (no hardcoded secrets)
- Health check endpoints for monitoring
- Container network isolation with Docker Compose
- Port binding only when needed (3000 for Rails, 5432/6379 for DBs)
- Redis password protection support
- Project-specific resource labeling for isolation
- Multi-stage builds reduce final image size
- Cached gem volumes prevent reinstallation
- Node modules caching speeds up asset compilation
- Minimal Alpine base for faster downloads
- Hot reloading with volume mounts
- Parallel service startup with dependency management
- Persistent data volumes prevent data loss
- Efficient cleanup commands for resource management
Container won't start:
# Check container status
./drun.sh ps
# View logs for debugging
./drun.sh logs rails
./drun.sh logs postgresDatabase connection issues:
# Ensure database is running
./drun.sh ps
# Check database logs
./drun.sh logs postgres
# Recreate database
./drun.sh rails db:drop db:create db:migratePermission errors:
# Clean up and rebuild
./drun.sh clean
./drun.sh buildPort conflicts:
# Change port in .env file
echo "PORT=3001" >> .env
./drun.sh down
./drun.sh serve- View all commands:
./drun.sh help - Check container status:
./drun.sh ps - View service logs:
./drun.sh logs [service] - Get suggested commands:
./drun.sh suggested
If you're already using Rails with Docker:
- Replace your existing
Dockerfileanddocker-compose.yml - Use
./drun.shinstead ofdocker-composecommands - Enjoy simplified commands and better security
If you're using Rails' docked tool:
drunprovides similar functionality with enhanced features- Better security with non-root user
- More comprehensive service stack (Redis, PostgreSQL)
- Simplified command interface
This project is licensed under the MIT License.
- Inspired by Docked by the Rails team
- Built with β€οΈ for the Rails community
- Special thanks to all contributors and users
Happy coding with drun! π
