Docker Development Setup
This guide will help you set up a complete Chatwoot development environment using Docker and Docker Compose.
Pre-requisites
Before proceeding, make sure you have the latest version of docker
and docker-compose
installed.
As of now, we recommend a version equal to or higher than the following:
$ docker --version
Docker version 25.0.4, build 1a576c5
$ docker compose --version
docker-compose version 2.24.7
Install Docker
Windows
Download Docker Desktop from https://www.docker.com/products/docker-desktop/
Run the installer and follow setup instructions
Enable WSL2 backend (recommended)
Restart your computer when prompted
macOS
# Option 1: Download from website
# Go to https://www.docker.com/products/docker-desktop/
# Option 2: Using Homebrew
brew install --cask docker
Linux (Ubuntu/Debian)
# Update package index
sudo apt update
# Install dependencies
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Add Docker repository
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $( lsb_release -cs ) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Add user to docker group
sudo usermod -aG docker $USER
# Start Docker service
sudo systemctl start docker
sudo systemctl enable docker
After adding yourself to the docker group on Linux, log out and log back in for the changes to take effect.
Development Environment
Clone the repository.
git clone https://github.com/chatwoot/chatwoot.git
Make a copy of the example environment file and modify it as required.
# Navigate to Chatwoot
cd chatwoot
cp .env.example .env
# Update redis and postgres passwords
nano .env
# Update docker-compose.yaml with the same postgres password
nano docker-compose.yaml
Build the images.
# Build base image first
docker compose build base
# Build the server and worker
docker compose build
After building the image or destroying the stack, you would have to reset the database using the following command.
docker compose run --rm rails bundle exec rails db:chatwoot_prepare
To run the app:
Access the rails app frontend by visiting http://0.0.0.0:3000/
Access Mailhog inbox by visiting http://0.0.0.0:8025/
(You will receive all emails going out of the application here)
Login with credentials
url: http://localhost:3000
user_name: john@acme.inc
password: Password1!
To stop the app:
Running RSpec Tests
For running the complete RSpec tests:
docker compose run --rm rails bundle exec rspec
For running specific test:
docker compose run --rm rails bundle exec rspec spec/ < path-to-fil e > : < line-numbe r >
Production Environment
To debug the production build locally, set SECRET_KEY_BASE
environment variable in your .env
file and then run the below commands:
docker compose -f docker-compose.production.yaml build
docker compose -f docker-compose.production.yaml up
Debugging Mode
To use debuggers like byebug
or binding.pry
, use the following command to bring up the app instead of docker compose up
:
docker compose run --rm --service-port rails
Development Workflow
Daily Development Commands
# Start development environment
docker compose up
# View logs
docker compose logs -f rails
# Access Rails console
docker compose exec rails bundle exec rails console
# Run migrations
docker compose exec rails bundle exec rails db:migrate
# Install new gems
docker compose exec rails bundle install
# Restart a service
docker compose restart rails
# Stop all services
docker compose down
# Stop and remove volumes (reset database)
docker compose down -v
Troubleshooting
If there is an update to any of the following:
dockerfile
gemfile
package.json
schema change
Make sure to rebuild the containers and run db:reset
.
docker compose down
docker compose build
docker compose run --rm rails bundle exec rails db:reset
docker compose up
Common Issues
Solution : Check service dependencies and logs:
# Check service status
docker compose ps
# Check logs for specific service
docker compose logs rails
# Restart problematic service
docker compose restart rails
Database connection refused
Solution : Ensure PostgreSQL container is healthy:
# Check postgres health
docker compose exec postgres pg_isready
# Restart postgres if needed
docker compose restart postgres
Solution : Stop other services using the same ports:
# Check what's using port 3000
lsof -i :3000
# Or change ports in docker-compose.yaml
Solution : Clean up Docker resources:
# Remove unused containers, networks, images
docker system prune -f
# Remove volumes (WARNING: This deletes data)
docker volume prune -f
# Remove everything (nuclear option)
docker system prune -a --volumes
Solution : Clear Docker cache and rebuild:
# Clear build cache
docker builder prune
# Rebuild without cache
docker compose build --no-cache
Getting Help
If you encounter Docker-specific issues:
Your Docker development environment is now ready for Chatwoot development! 🐳