This project includes Docker Compose configurations for both production and test environments.
- Docker
- Docker Compose
- Rails master key (in
config/master.keyor as environment variable)
The production environment uses PostgreSQL and runs the Rails app in production mode.
# Set your Rails master key
export RAILS_MASTER_KEY=$(cat config/master.key)
# Start the services
docker-compose up -d
# View logs
docker-compose logs -f webThe application will be available at http://localhost
- web: Rails application (port 80)
- db: PostgreSQL database (port 5432)
# Run migrations
docker-compose exec web bin/rails db:migrate
# Access Rails console
docker-compose exec web bin/rails console
# Stop services
docker-compose down
# Stop and remove volumes (WARNING: deletes data)
docker-compose down -vThe test environment includes live reloading and is designed for running tests in isolation.
# Start test database and run tests
docker-compose -f docker-compose.test.yml up
# Run tests in watch mode (requires additional setup)
docker-compose -f docker-compose.test.yml run --rm test bundle exec rspec
# Run specific test file
docker-compose -f docker-compose.test.yml run --rm test bundle exec rspec spec/models/user_spec.rb- test: Rails test environment with live code reloading
- db_test: PostgreSQL test database (port 5433)
# Run tests interactively
docker-compose -f docker-compose.test.yml run --rm test bash
# Then inside container:
bundle exec rspec
# Reset test database
docker-compose -f docker-compose.test.yml run --rm test bin/rails db:test:prepare
# Stop test services
docker-compose -f docker-compose.test.yml downThe test environment mounts your local code directory as a volume, so changes to your code are immediately reflected in the container. This allows for rapid test-driven development:
- Edit code locally
- Run tests in the container
- See results immediately
# Connect to production database
docker-compose exec db psql -U medtracker -d medtracker_production# Connect to test database
docker-compose -f docker-compose.test.yml exec db_test psql -U medtracker_test -d medtracker_testIf you see database connection errors:
# Check database is healthy
docker-compose ps
# View database logs
docker-compose logs db
# Restart database
docker-compose restart dbIf you encounter permission issues with volumes:
# Fix ownership (run from host)
sudo chown -R $USER:$USER storage/ log/ tmp/To start fresh:
# Stop all services and remove volumes
docker-compose down -v
docker-compose -f docker-compose.test.yml down -v
# Rebuild images
docker-compose build --no-cache
docker-compose -f docker-compose.test.yml build --no-cache- The production Dockerfile is optimized for size and security
- The test Dockerfile includes development dependencies
- Both environments use PostgreSQL 16 Alpine for efficiency
- Volumes persist data between container restarts
- The test environment uses separate ports to avoid conflicts