Example
Tutorial
In this comprehensive tutorial, we will create a scalable web application using Docker Compose and configure it with Hawiyat's infrastructure. You'll learn how to:
- Set up a containerized Next.js application
- Configure Traefik reverse proxy for routing
- Enable automatic SSL certificate generation
- Implement proper networking between services
- Deploy the application with high availability
Prerequisites
- A Hawiyat account with admin access
- Basic understanding of Docker and Docker Compose
- A domain name that you can configure
- Git installed on your local machine
- Basic familiarity with YAML syntax
Steps
- Create a new project.
- Create a new service
Compose
and select the Compose TypeDocker Compose
. - Fork this repository: Repo.
- Select Provider type: GitHub or Git.
- Select the repository:
hawiyat/docker-compose-test
. - Select the branch:
main
. - Set the Compose Path to
./docker-compose.yml
and save.
Understanding the Configuration Requirements
Before updating your Docker Compose configuration, it's important to understand the key components that make your application work with Hawiyat:
-
Network Configuration
- The
hawiyat-network
is a managed network that enables communication between your services - All containers must be connected to this network to ensure proper service discovery
- The network is created and managed by Hawiyat automatically
- The
-
Traefik Integration
- Traefik serves as the edge router for all incoming traffic
- Labels are used to configure routing rules and SSL certificates
- Each service requires specific Traefik labels for proper routing
Updating Your docker-compose.yml
To integrate your application with Hawiyat's infrastructure, you need to make the following modifications to your docker-compose.yml
file:
- Add the
hawiyat-network
to each service to enable proper communication - Configure Traefik labels for:
- Enabling Traefik routing
- Setting up domain rules
- Configuring SSL endpoints
- Defining service ports
- Remove any conflicting network configurations
- Adjust port mappings to avoid conflicts
Example:
Let's modify the following compose file to make it work with hawiyat:
Updated version with hawiyat-network and Traefik labels:
Don't set container_name property to the each service, it will cause issues with logs, metrics and other features
Make sure to point the A record to the domain you want to use for your service.

Deploy the application by clicking on "deploy" and wait for the deployment to complete. Then give Traefik about 10 seconds to generate the certificates. You can then access the application through the domain you have set.

Important Configuration Details
Naming Conventions and Best Practices
-
Router Naming
- Set unique names for each router:
traefik.http.routers.<unique-name>
- Use descriptive names that reflect the service purpose
- Example:
myapp-web
,myapp-api
,myapp-frontend
- Set unique names for each router:
-
Service Naming
- Set unique names for each service:
traefik.http.services.<unique-name>
- Keep service names consistent with router names
- Avoid generic names like "web" or "app"
- Set unique names for each service:
-
Network Configuration
- Always ensure services are linked to
hawiyat-network
- Remove any custom network definitions
- Don't create additional overlay networks unless necessary
- Always ensure services are linked to
-
SSL and Security
- Use
websecure
entrypoint for HTTPS traffic - Configure
letsencrypt
as the certificate resolver - SSL certificates are automatically generated and renewed
- Ensure your domain's DNS is properly configured
- Use
-
Performance Optimization
- Use the
restart: always
policy for production services - Configure appropriate healthcheck parameters
- Set reasonable resource limits
- Use proper logging configurations
- Use the
Troubleshooting Common Issues
-
Certificate Generation
- Allow up to 1 minute for initial certificate generation
- Verify DNS records are properly configured
- Check Traefik logs if certificates aren't generating
-
Network Connectivity
- Ensure all services are on
hawiyat-network
- Verify port configurations
- Check for port conflicts
- Ensure all services are on
-
Service Discovery
- Use proper service names in your configurations
- Verify Traefik labels are correctly formatted
- Check for typos in domain names