Domains
Configure domains for your Docker Compose application.
When using Docker Compose, there are two ways to configure domains for your services:
Method 1: Using Nomploy Domains (Recommended)
The easiest way to configure domains is using Nomploy's native domain management feature. This method allows you to configure domains directly through the Nomploy UI without manually editing your Docker Compose file.
Recommended: Since v0.7.0, Nomploy supports domains natively. You can configure your domains directly in the Nomploy UI through the Domains tab of your Docker Compose application. This is the simplest and most user-friendly approach.
To use this method:
- Navigate to your Docker Compose application in Nomploy
- Go to the Domains tab
- Click Add Domain and configure your domain
- Nomploy will automatically handle the routing configuration
How It Works
At runtime, during the deployment phase, Nomploy automatically adds Traefik labels internally to your Docker Compose file. You don't need to manually add these labels - Nomploy handles this automatically based on the domains you configure in the UI.
Example:
Here's a default Docker Compose file:
version: "3.8"
services:
beszel:
image: henrygd/beszel:0.10.2
restart: unless-stopped
ports:
- 8090
volumes:
- beszel_data:/beszel_data
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
beszel_data: {}Preview Compose Feature:
You can click the Preview Compose button to see the final Docker Compose file that will be executed. If you have at least one domain added, the preview will show the compose file with all the labels and network configurations automatically added.
Here's what the final compose file looks like when deployed (this example uses Isolated Deployments):
version: "3.8"
services:
beszel:
image: henrygd/beszel:0.10.2
restart: unless-stopped
ports:
- 8090
volumes:
- beszel_data:/beszel_data
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- a-beszel-a95pzl
labels:
- traefik.http.routers.a-beszel-a95pzl-715-web.rule=Host(`a-beszel-d073ee-31-220-108-27.traefik.me`)
- traefik.http.routers.a-beszel-a95pzl-715-web.entrypoints=web
- traefik.http.services.a-beszel-a95pzl-715-web.loadbalancer.server.port=8090
- traefik.http.routers.a-beszel-a95pzl-715-web.service=a-beszel-a95pzl-715-web
- traefik.enable=true
volumes:
beszel_data: {}
networks:
a-beszel-a95pzl:
name: a-beszel-a95pzl
external: trueImportant Notes:
- If you don't add any domains through the UI and don't use Isolated Deployments, your application will be deployed exactly as you specified in your original Docker Compose file - no labels or network modifications will be added.
- If you're not using Isolated Deployments, Nomploy will add the
nomploy-networkto the service you selected, however you need to addnomploy-networkto the other services to maintain connectivity. - The Preview Compose button is useful for verifying how Nomploy will modify your compose file before deployment.
- All label generation and network configuration is handled automatically by Nomploy based on your domain settings.
For detailed instructions on using Nomploy's domain management, see the Domains guide.
Method 2: Manual Configuration (Advanced)
If you prefer to configure domains manually using Traefik labels in your Docker Compose file, you can do so by following the steps below. This method gives you more control but requires manual configuration.
Manual configuration is more complex and requires editing your Docker Compose file. We recommend using Method 1 (Nomploy Domains) unless you have specific requirements that need manual Traefik label configuration.
Manual Configuration Steps
Key Steps for manual configuration:
- Add the service to the
nomploy-network. - Use Traefik labels to configure routing.
Example Scenario
Let's consider an application with three components: a frontend, a backend, and a database. We'll start with a basic Docker Compose file and then enhance it with manual domain configuration.
version: "3.8"
services:
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
volumes:
- ./frontend:/app
ports:
- "3000:3000"
depends_on:
- backend
backend:
build:
context: ./backend
dockerfile: Dockerfile
volumes:
- ./backend:/app
ports:
- "5000:5000"
environment:
- DATABASE_URL=postgres://postgres:password@database:5432/mydatabase
depends_on:
- database
database:
image: postgres:13
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: mydatabase
volumes:
- db-data:/var/lib/postgresql/data
volumes:
db-data:Step 1: Add the Network
First, we'll add the nomploy-network to our services:
Tip: If you prefer to isolate all services and avoid adding them to the nomploy-network, you can use the Isolated Deployments feature. This feature isolates all services and eliminates the need to manually add them to the nomploy-network. See the Isolated Deployments guide for more information.
version: "3.8"
services:
frontend:
# ... (previous configuration)
networks:
- nomploy-network
backend:
# ... (previous configuration)
networks:
- nomploy-network
database:
# ... (previous configuration)
networks:
- nomploy-network
volumes:
db-data:
networks:
nomploy-network:
external: trueStep 2: Configuring Traefik Labels
Now, let's add Traefik labels to route domains to our services. We'll focus on the frontend and backend services:
version: "3.8"
services:
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
volumes:
- ./frontend:/app
expose:
- 3000
depends_on:
- backend
networks:
- nomploy-network
labels:
- traefik.enable=true
- traefik.http.routers.frontend-app.rule=Host(`frontend.nomploy.com`)
- traefik.http.routers.frontend-app.entrypoints=web
- traefik.http.services.frontend-app.loadbalancer.server.port=3000
backend:
build:
context: ./backend
dockerfile: Dockerfile
volumes:
- ./backend:/app
expose:
- 5000
environment:
- DATABASE_URL=postgres://postgres:password@database:5432/mydatabase
depends_on:
- database
networks:
- nomploy-network
labels:
- traefik.enable=true
- traefik.http.routers.backend-app.rule=Host(`backend.nomploy.com`)
- traefik.http.routers.backend-app.entrypoints=web
- traefik.http.services.backend-app.loadbalancer.server.port=5000
database:
# ... (same as before)
volumes:
db-data:
networks:
nomploy-network:
external: trueUnderstanding Traefik Labels
traefik.enable=trueEnables Traefik routing for the service.traefik.http.routers.<UNIQUE-RULE>.rule=Host('your-domain.nomploy.com')Specifies the domain for the servicetraefik.http.routers.<UNIQUE-RULE>.entrypoints=webSets the service to be accessible via HTTP.traefik.http.services.<UNIQUE-RULE>.loadbalancer.server.port=3000Specifies the port your service is using internally.
Note: Replace <UNIQUE-RULE> with a unique identifier for each service (e.g., frontend-app, backend-app, etc.).
Important Considerations
- Port Exposure: Use
exposeinstead ofportsto limit port access to the container network, avoiding exposure to the host machine. - DNS Configuration: Ensure you create
Arecords pointing to your domain in your DNS Provider Settings. - HTTPS: For HTTPS, you can use Let's Encrypt or other SSL/TLS certificates.
- Isolated Deployments: As an alternative to manually adding services to
nomploy-network, you can use the Isolated Deployments feature, which automatically isolates all services and handles networking configuration for you.
Deployment
With these manual configurations in place, you're now ready to deploy your application using Docker Compose. This setup should be sufficient to get your services up and running with custom domain routing through Traefik.
Remember: For most use cases, we recommend using Method 1 (Nomploy Domains) as it's simpler and doesn't require manual Docker Compose file editing. See the Domains guide for more information.
If you have any further questions or need assistance, ask on our GitHub Discussions and we'll be happy to help.