This document explains how to use Docker with the Webhook Integration App, a Rails 8 application using Solid Adapters and Propshaft asset pipeline.
- Docker and Docker Compose installed
- Environment-specific credentials keys (for production)
-
Set up environment variables:
# For production, you only need the production credentials key export RAILS_MASTER_KEY=your_production_credentials_key
-
Build and start the application:
docker-compose up --build
-
Access the application:
- Web application:
http://localhost:3000 - Database:
localhost:5432(not to expose in production, use a secure connection)
- Web application:
-
Environment variables setup:
This application now uses dotenv-rails for development environment variables. Make sure you have an
.envfile in your project root with necessary configuration (database credentials, etc.):# Example .env file for development POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres # Add other development environment variables here
-
Start development environment:
docker-compose -f docker-compose.dev.yml up --build
This automatically sets up the database, runs migrations, and starts all services.
Note: Rails is configured to bind to
0.0.0.0in development (seeProcfile.dev) so it is accessible from your host athttp://localhost:3000.
- app: Rails application server
- db: PostgreSQL database
- app: Rails development server with hot reloading (binds to 0.0.0.0)
- db: PostgreSQL database
RAILS_MASTER_KEY: Production credentials key for decryptingconfig/credentials/production.yml.enc
- Uses dotenv-rails gem to load variables from
.envfile - Rails Master Key is in the .env file.
The following variables are already configured in the docker-compose files:
MAILER_HOST=localhost:3000: Host for mailer URLsRAILS_MAX_THREADS=5: Maximum database connection pool sizeRAILS_LOG_LEVEL=info: Log level
You can override the pre-configured variables by setting environment variables:
# Override MAILER_HOST for production
export MAILER_HOST=your-domain.com
docker-compose up --build- Default:
config/credentials.yml.enc(key stored inconfig/master.key)
To work with your Rails credentials:
-
Check existing credential files:
find ./config -name "*.yml.enc" -o -name "*.key"
-
Edit credentials:
# For development rails credentials:edit --environment development # For production rails credentials:edit --environment production # For default credentials rails credentials:edit
-
View credentials:
# For development rails credentials:show --environment development # For production rails credentials:show --environment production # For default credentials rails credentials:show
The application uses multiple PostgreSQL databases for different purposes:
- Primary: Main application data
- Queue: Background job queue (Solid Queue)
- Cable: Action Cable real-time features (Solid Cable)
- Cache: Application caching (Solid Cache)
The Docker setup automatically creates all required databases using:
- Environment Variable:
POSTGRES_MULTIPLE_DATABASESlists all databases to create - Automatic Setup: Databases are created when PostgreSQL container starts
The application uses TCP connections to the database container:
- Connection URLs: Use
postgres://postgres:postgres@db:5432/database_name - Container Networking: Uses Docker's internal networking
- No Unix Sockets: Avoids local socket connection issues
The application now includes automated database setup:
- Entrypoint Script:
bin/docker-entrypointhandles database initialization - Migration Automation: Only the app service runs migrations to prevent race conditions
- Health Checks: Services wait for dependencies to be healthy before starting
- No Manual Setup: Database setup is fully automated on startup
This application uses Rails 8's modern asset pipeline:
- Propshaft: Asset pipeline (replaces Sprockets)
- Importmap Rails: JavaScript dependency management
- Tailwind CSS Rails: CSS framework via gem
- No Node.js required: All assets are compiled through Rails
The services include comprehensive health checks:
- Database: Checks PostgreSQL connectivity using
pg_isready - App: Checks
/healthendpoint to verify Rails application is ready - Dependencies: Services wait for their dependencies to be healthy
The application includes a /health endpoint for Docker health checks:
# config/routes.rb
get '/health', to: proc { [200, {}, ['OK']] }Note: Use bin/rails (not just rails) for all Rails commands inside the container.
# View logs
docker-compose logs -f app
# Run Rails console
docker-compose exec app bin/rails console
# Run database migrations
docker-compose exec app bin/rails db:migrate
# Precompile assets
docker-compose exec app bin/rails assets:precompile
# Restart services
docker-compose restart app
# Stop all services
docker-compose down# View logs
docker-compose -f docker-compose.dev.yml logs -f app
# Run Rails console
docker-compose -f docker-compose.dev.yml exec app bin/rails console
# Run RSpec
docker-compose -f docker-compose.dev.yml exec app bundle exec rspec
# Access database
docker-compose -f docker-compose.dev.yml exec db psql -U postgres -d webhook_integration_app_development
# Watch and compile assets
docker-compose -f docker-compose.dev.yml exec app bin/rails tailwindcss:watch-
Permission errors:
sudo chown -R $USER:$USER .
-
Database connection issues:
# Remove all containers and volumes docker-compose down -v docker-compose up --build -
Asset compilation errors:
docker-compose exec app bin/rails assets:precompile -
Tailwind CSS not compiling:
docker-compose exec app bin/rails tailwindcss:build -
Credentials errors:
# For development: # Verify the master.key file exists ls -la config/master.key # Verify credentials can be decrypted docker-compose -f docker-compose.dev.yml exec app bin/rails credentials:show # For production: # Check if RAILS_MASTER_KEY is set echo $RAILS_MASTER_KEY # Verify credentials can be decrypted docker-compose exec app bin/rails credentials:show --environment production
-
Database not found errors:
# Check if databases exist docker-compose exec db psql -U postgres -l # Recreate databases if needed docker-compose down -v docker-compose up --build
-
Race condition errors (migrations running simultaneously):
# The new setup prevents this, but if you see it: docker-compose down -v docker-compose up --build -
Cannot access Rails app at
http://localhost:3000:- Ensure Rails is started with
-b 0.0.0.0(seeProcfile.dev) - Ensure Docker Compose port mapping is
3000:3000 - Try both
http://localhost:3000andhttp://127.0.0.1:3000 - Check for firewalls, VPNs, or security software blocking Docker traffic
- Check logs with
docker-compose -f docker-compose.dev.yml logs -f app
- Ensure Rails is started with
# Remove all volumes (WARNING: This will delete all data)
docker-compose down -v
# Backup database
docker-compose exec db pg_dump -U postgres webhook_integration_app_production > backup.sql
# Restore database
docker-compose exec -T db psql -U postgres webhook_integration_app_production < backup.sql- Enable asset caching with Propshaft
- Use connection pooling
- Monitor resource usage
- Precompile assets during build
- Use volume mounts for hot reloading
- Cache bundle dependencies
- Enable debugging tools
- Use Tailwind CSS watch mode for live CSS updates
- Never commit credential keys
- Use environment variables for secrets
- Run containers as non-root user
- Keep base images updated
- Use health checks for monitoring
- No Node.js dependencies reduces attack surface
For production deployment, consider using:
- Kamal: Rails deployment tool
- Docker Swarm: Container orchestration
- Kubernetes: Container orchestration
- Reverse proxy: Nginx or Traefik
Monitor the application using:
# Resource usage
docker stats
# Log analysis
docker-compose logs --tail=100 app
# Database connections
docker-compose exec db psql -U postgres -c "SELECT * FROM pg_stat_activity;"
# Asset compilation status
docker-compose exec app bin/rails assets:environment
# Database status
docker-compose exec db psql -U postgres -l
# Health check status
docker-compose psThe Dockerfiles are optimized for Rails 8:
- Multi-stage builds: Separate build and runtime stages
- Propshaft assets: No Node.js required for asset compilation
- Bootsnap precompilation: Faster application startup
- Minimal dependencies: Only essential packages installed
- Security: Non-root user execution
- Database initialization: Automatic setup of all required databases
- Entrypoint scripts: Automated database setup and migration handling
- Health checks: Comprehensive service health monitoring