Skip to content

Commit

Permalink
- Added Traefik to support multiple projects at a time
Browse files Browse the repository at this point in the history
- Added Traefik instructions under traefik.md
- Added test directory to test Traefik for two projects
- Updated README for Traefik
- Moved standard docker setup under standard-setup directory
  • Loading branch information
adnnor committed Nov 4, 2024
1 parent 7bd330e commit dc030aa
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 85 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Changelog

## [1.1.0]
- Added Traefik to support multiple projects at a time
- Added Traefik instructions under traefik.md
- Added test directory to test Traefik for two projects
- Updated README for Traefik
- Moved standard docker setup under standard-setup directory

## [1.0.3]
- Fixed TOC in READMe
- Fixed TOC in README
- Fixed issues with PostGresQL

## [1.0.2]
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This guide provides an overview of managing your docker setup that includes PHP,
- [docker-compose.yml](#docker-composeyml)
- [Services](#services)
- [app](#app)
- [traefik](#traefik)
- [phpfpm](#phpfpm)
- [supervisor](#supervisor)
- [postgres](#postgres)
Expand Down Expand Up @@ -42,6 +43,8 @@ Contains configuration files for various services.
- `nginx.default.conf`: Nginx configuration file.
- `.env-app.local`: Environment file for Oro Commerce.
- `supervisord.conf`: Supervisor configuration to manage background processes.
- `traefik.yml`: Traefik configuration for routing and services.
- `acme.json`: File for storing SSL certificates used by Traefik.

#### src
The base directory where the application source code is located. Mounted to `/var/www/html` within containers.
Expand Down Expand Up @@ -89,6 +92,19 @@ Nginx is configured to serve PHP applications, utilizing FastCGI for processing
4. **Logs**
Access and error logs are located at `/var/log/nginx/access.log` and `/var/log/nginx/error.log`, respectively. Monitor these logs for troubleshooting and performance analysis.

## traefik[](#table-of-contents)

Traefik makes running multiple Docker projects easy with a few adjustments. By setting `COMPOSE_PROJECT_NAME` in a `.env` file, you assign unique project names, isolating container and network names to avoid conflicts. Setting unique hostnames in Traefik labels allows each instance to route traffic to its own services, ensuring projects run independently with separate configurations and customized routing.

If you skip setting `COMPOSE_PROJECT_NAME`, Docker Compose defaults to the directory name as the project name. While this can prevent conflicts, explicitly defining project names provides more control and avoids potential confusion in complex directory setups.

Traefik can be used for both single and multi-project setups. Traefik is great for handling automated routing, load balancing, and hostname management, but if you don’t need advanced routing, you can easily manage ports and networks manually.

For simpler setup, check out the standard Docker guide [here](./standard-setup) if you’re working on a single project.

For guidance on configuring multiple Docker projects with Traefik, refer to the [instructions here](./traefik.md).


## phpfpm[](#table-of-contents)

Installed PHP extensions are: `bcmath`, `bz2`, `calendar`, `exif`, `ftp`, `gd`, `gettext`, `intl`, `mbstring`, `opcache`, `pcntl`, `soap`, `sockets`, `sodium`, `sysvmsg`, `sysvsem`, `sysvshm`, `xsl`, `zip`
Expand Down
File renamed without changes.
File renamed without changes.
78 changes: 47 additions & 31 deletions test/mood/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ services:
- oro
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./traefik.yml:/etc/traefik/traefik.yml"
- "./acme.json:/acme.json"
- "./conf/traefik.yml:/etc/traefik/traefik.yml"
- "./conf/acme.json:/acme.json"
labels:
- "traefik.enable=true"
# Dashboard access
- "traefik.http.routers.traefik-dashboard-mood.rule=Host(`traefik.mood.local`)"
- "traefik.http.routers.traefik-dashboard-mood.service=api@internal"
#- "traefik.http.services.traefik-dashboard-mood.loadbalancer.server.port=8080"

# supervisor:
# image: adnnor/supervisor
# volumes:
# - ./src:/var/www/html
# - ./conf/supervisord.conf:/etc/supervisord.conf
# depends_on:
# - phpfpm
# networks:
# - oro
# restart: always
# command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisord -n"
supervisor:
image: adnnor/supervisor
volumes:
- ./src:/var/www/html
- ./conf/supervisord.conf:/etc/supervisord.conf
depends_on:
- phpfpm
networks:
- oro
restart: always
command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisord -n"

postgres:
image: postgres:latest
Expand Down Expand Up @@ -92,9 +92,11 @@ services:
image: adnnor/elasticsearch:8.4
labels:
- "traefik.enable=true"
- "traefik.http.routers.elasticsearch.rule=Host(`elasticsearch.mood.local`)"
- "traefik.http.services.elasticsearch.loadbalancer.server.port=9200"
- "traefik.http.routers.elasticsearch-mood.rule=Host(`elasticsearch.mood.local`)"
- "traefik.http.services.elasticsearch-mood.loadbalancer.server.port=9200"
env_file: env/elasticsearch.env
networks:
- oro
environment:
- "discovery.type=single-node"
## Avoid test failures due to small disks
Expand All @@ -105,25 +107,39 @@ services:
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
## Uncomment to increase the virtual memory map count
- "max_map_count=262144"
## Prefer to disable security features on local
- "xpack.security.enabled=false"

# redis:
# image: redis:6.0-alpine
# ports:
# - "6379:6379"
redis:
image: redis:6.0-alpine
networks:
- oro
labels:
- "traefik.enable=true"
- "traefik.tcp.services.redis-mood.loadbalancer.server.port=6379"

# rabbitmq:
# image: rabbitmq:3.11-management-alpine
# ports:
# - "15672:15672"
# - "5672:5672"
# volumes:
# - rabbitmqdata:/var/lib/rabbitmq
# env_file: env/rabbitmq.env
rabbitmq:
image: rabbitmq:3.11-management-alpine
volumes:
- rabbitmqdata:/var/lib/rabbitmq
env_file: env/rabbitmq.env
networks:
- oro
labels:
- "traefik.enable=true"
- "traefik.http.routers.rabbitmq-ui-mood.rule=Host(`rabbitmq.mood.local`)" # UI access
- "traefik.http.services.rabbitmq-ui-mood.loadbalancer.server.port=15672"
- "traefik.tcp.services.rabbitmq-amqp-mood.loadbalancer.server.port=5672"

# mailcatcher:
# image: sj26/mailcatcher
# ports:
# - "1080:1080"
mailcatcher:
image: sj26/mailcatcher
networks:
- oro
labels:
- "traefik.enable=true"
- "traefik.http.routers.mailcatcher-mood.rule=Host(`mailcatcher.mood.local`)"
- "traefik.http.services.mailcatcher-mood.loadbalancer.server.port=1080"


networks:
oro:
Expand Down
File renamed without changes.
File renamed without changes.
63 changes: 33 additions & 30 deletions test/vibe/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ services:
- oro
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./traefik.yml:/etc/traefik/traefik.yml"
- "./acme.json:/acme.json"
- "./conf/traefik.yml:/etc/traefik/traefik.yml"
- "./conf/acme.json:/acme.json"
labels:
- "traefik.enable=true"
# Dashboard access
- "traefik.http.routers.traefik-dashboard-vibe.rule=Host(`traefik.vibe.local`)"
- "traefik.http.routers.traefik-dashboard-vibe.service=api@internal"
#- "traefik.http.services.traefik-dashboard-vibe.loadbalancer.server.port=8083"

# supervisor:
# image: adnnor/supervisor
# volumes:
# - ./src:/var/www/html
# - ./conf/supervisoro2network.conf:/etc/supervisoro2network.conf
# depends_on:
# - phpfpm
# networks:
# - oro
# restart: always
# command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisoro2network -n"
supervisor:
image: adnnor/supervisor
volumes:
- ./src:/var/www/html
- ./conf/supervisord.conf:/etc/supervisord.conf
depends_on:
- phpfpm
networks:
- oro
restart: always
command: /bin/sh -c "rm -f /tmp/supervisor.sock && supervisoro2network -n"

postgres:
image: postgres:latest
Expand Down Expand Up @@ -105,24 +105,27 @@ services:
## Uncomment to increase the virtual memory map count
- "max_map_count=262144"

# redis:
# image: redis:6.0-alpine
# ports:
# - "6379:6379"

# rabbitmq:
# image: rabbitmq:3.11-management-alpine
# ports:
# - "15672:15672"
# - "5672:5672"
# volumes:
# - rabbitmqdata:/var/lib/rabbitmq
# env_file: env/rabbitmq.env
rabbitmq:
image: rabbitmq:3.11-management-alpine
volumes:
- rabbitmqdata:/var/lib/rabbitmq
env_file: env/rabbitmq.env
networks:
- oro
labels:
- "traefik.enable=true"
- "traefik.http.routers.rabbitmq-ui-vibe.rule=Host(`rabbitmq.vibe.local`)" # UI access
- "traefik.http.services.rabbitmq-ui-vibe.loadbalancer.server.port=15672"
- "traefik.tcp.services.rabbitmq-amqp-vibe.loadbalancer.server.port=5672"

# mailcatcher:
# image: sj26/mailcatcher
# ports:
# - "1080:1080"
mailcatcher:
image: sj26/mailcatcher
networks:
- oro
labels:
- "traefik.enable=true"
- "traefik.http.routers.mailcatcher-vibe.rule=Host(`mailcatcher.vibe.local`)"
- "traefik.http.services.mailcatcher-vibe.loadbalancer.server.port=1080"

networks:
oro:
Expand Down
58 changes: 35 additions & 23 deletions traefik.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
# Traefik
# Multi-Project Setup with Traefik

TODOs
This guide covers setting up multiple isolated Docker projects using Traefik for automated routing and load balancing. Starting with an example project, `mood`, you’ll quickly replicate the setup for additional projects like `vibe`, each with its unique URLs and independent configuration. Perfect for managing multiple Oro environments efficiently with Traefik.

Correct PHP extensions under phpfpm remove mysql add pdo or postgres
Correct path of Credits in TOC
Upload Change log to master
rename test-traefik to test
rename project1 to mood
rename project2 to vibe
When integrating Traefik into your Docker setup, it's important to note that your existing hostnames for services like PostgreSQL, Elasticsearch, Redis, and RabbitMQ will remain unchanged. You will continue to access:

- PostgreSQL at `postgres`
- Elasticsearch at `elasticsearch`
- Redis at `redis`
- RabbitMQ at `rabbitmq`

For example, when connecting to the PostgreSQL database, you can use the following command with the username and password set to `root`:

```bash
psql -h postgres -U root -d dev
```

Traefik makes running multiple Docker projects easy with a few adjustments. By setting `COMPOSE_PROJECT_NAME` in a `.env` file, you assign unique project names, isolating container and network names to avoid conflicts. Setting unique hostnames in Traefik labels allows each instance to route traffic to its own services, ensuring projects run independently with separate configurations and customized routing.

If you skip setting `COMPOSE_PROJECT_NAME`, Docker Compose defaults to the directory name as the project name. While this can prevent conflicts, explicitly defining project names provides more control and avoids potential confusion in complex directory setups.

Traefik can be used for both single and multi-project setups. Traefik is great for handling automated routing, load balancing, and hostname management, but if you don’t need advanced routing, you can easily manage ports and networks manually.

For simpler setup, check out the standard Docker guide [here](./standard-setup) if you’re working on a single project.

This consistency ensures that while Traefik enhances your routing and management capabilities, your service URLs remain the same, preventing any confusion in your workflow.

## Table of Contents

Expand Down Expand Up @@ -61,14 +57,24 @@ Next, create a new directory named `mood`, clone this repository into it, and en

Add the following URLs to your `/etc/hosts` file:

- `mood.local`
- `pgadmin.mood.local`
- `traefik.mood.local`
- 127.0.0.1 mood.local
- 127.0.0.1 pgadmin.mood.local
- 127.0.0.1 traefik.mood.local
- 127.0.0.1 rabbitmq.mood.local
- 127.0.0.1 mailcatcher.mood.local
- 127.0.0.1 elasticsearch.mood.local

Run `docker-compose up -d` to start the containers. Ensure you have Docker set up on your machine; if not, please refer to the official documentation and **confirm that Docker is running without requiring sudo**.

Once the command successfully brings up all the services, you’ll be able to access the specified URLs.

- `mood.local`: The primary URL for accessing the main application.
- `pgadmin.mood.local`: Access the pgAdmin interface for managing your PostgreSQL databases.
- `traefik.mood.local`: The entry point for the Traefik dashboard to monitor and manage routes.
- `rabbitmq.mood.local`: Connect to the RabbitMQ management interface for messaging services.
- `mailcatcher.mood.local`: View and manage captured emails during development via Mailcatcher.
- `elasticsearch.mood.local`: Access the Elasticsearch interface for managing search indexes and queries.

## Setup another project

Now, To start another Docker project with the same setup, you can duplicate the existing directory, like `mood` in this example:
Expand All @@ -81,7 +87,7 @@ This command creates an exact copy of `mood` in a new directory called `vibe`, i

Next, open the `docker-compose.yml` file in the `vibe` directory. Replace all instances of `"mood"` with `"vibe"` throughout the file.

Under the `traefik` service in `docker-compose.yml`, update the `ports` section to avoid conflicts with the first project:
Under the `traefik` service in `docker-compose.yml`, update the `ports` section to avoid conflicts with the first project also make sure they are not in use by any other resources:

```yaml
ports:
Expand All @@ -107,9 +113,12 @@ Note that while `nginx.conf` supports secure URLs, SSL is not yet set up here. Y

Add the following URLs to your `/etc/hosts` file:

- `vibe.local`
- `pgadmin.vibe.local`
- `traefik.vibe.local`
- 127.0.0.1 vibe.local
- 127.0.0.1 pgadmin.vibe.local
- 127.0.0.1 traefik.vibe.local
- 127.0.0.1 rabbitmq.vibe.local
- 127.0.0.1 mailcatcher.vibe.local
- 127.0.0.1 elasticsearch.vibe.local

After making these changes, start the project by running:

Expand All @@ -122,4 +131,7 @@ This will set up `vibe` as a separate project with the following URLs:
- `vibe.local:8088`
- `pgadmin.vibe.local:8088`
- `traefik.vibe.local:8088`
- `rabbitmq.vibe.local:8088`
- `mailcatcher.vibe.local:8088`
- `elasticsearch.vibe.local:8088`

0 comments on commit dc030aa

Please sign in to comment.