Skip to content

Commit eb0c941

Browse files
luiscoutinhbestlong
authored andcommitted
Add traefik (laradock#1916)
* Add mosquitto broker * Add documetation to mosquitto * Add traefik
1 parent d27f436 commit eb0c941

6 files changed

Lines changed: 136 additions & 1 deletion

File tree

DOCUMENTATION/content/documentation/index.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,87 @@ docker-compose up -d grafana
11211121

11221122

11231123

1124+
<br>
1125+
<a name="Use-Traefik"></a>
1126+
## Use Traefik
1127+
1128+
To use Traefik you need to do some changes in `traefik/trafik.toml` and `docker-compose.yml`.
1129+
1130+
1 - Open `traefik.toml` and change the `e-mail` property in `acme` section.
1131+
1132+
2 - Change your domain in `acme.domains`. For example: `main = "example.org"`
1133+
1134+
2.1 - If you have subdomains, you must add them to `sans` property in `acme.domains` section.
1135+
1136+
```bash
1137+
[[acme.domais]]
1138+
main = "example.org"
1139+
sans = ["monitor.example.org", "pma.example.org"]
1140+
```
1141+
1142+
3 - If you need to add basic authentication (https://docs.traefik.io/configuration/entrypoints/#basic-authentication), you just need to add the following text after `[entryPoints.https.tls]`:
1143+
1144+
```bash
1145+
[entryPoints.https.auth.basic]
1146+
users = ["user:password"]
1147+
```
1148+
1149+
4 - You need to change the `docker-compose.yml` file to match the Traefik needs. If you want to use Traefik, you must not expose the ports of each container to the internet, but specify some labels.
1150+
1151+
4.1 For example, let's try with NGINX. You must have:
1152+
1153+
```bash
1154+
nginx:
1155+
build:
1156+
context: ./nginx
1157+
args:
1158+
- PHP_UPSTREAM_CONTAINER=${NGINX_PHP_UPSTREAM_CONTAINER}
1159+
- PHP_UPSTREAM_PORT=${NGINX_PHP_UPSTREAM_PORT}
1160+
- CHANGE_SOURCE=${CHANGE_SOURCE}
1161+
volumes:
1162+
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
1163+
- ${NGINX_HOST_LOG_PATH}:/var/log/nginx
1164+
- ${NGINX_SITES_PATH}:/etc/nginx/sites-available
1165+
depends_on:
1166+
- php-fpm
1167+
networks:
1168+
- frontend
1169+
- backend
1170+
labels:
1171+
- traefik.backend=nginx
1172+
- traefik.frontend.rule=Host:example.org
1173+
- traefik.port=80
1174+
```
1175+
1176+
instead of
1177+
1178+
```bash
1179+
nginx:
1180+
build:
1181+
context: ./nginx
1182+
args:
1183+
- PHP_UPSTREAM_CONTAINER=${NGINX_PHP_UPSTREAM_CONTAINER}
1184+
- PHP_UPSTREAM_PORT=${NGINX_PHP_UPSTREAM_PORT}
1185+
- CHANGE_SOURCE=${CHANGE_SOURCE}
1186+
volumes:
1187+
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
1188+
- ${NGINX_HOST_LOG_PATH}:/var/log/nginx
1189+
- ${NGINX_SITES_PATH}:/etc/nginx/sites-available
1190+
- ${NGINX_SSL_PATH}:/etc/nginx/ssl
1191+
ports:
1192+
- "${NGINX_HOST_HTTP_PORT}:80"
1193+
- "${NGINX_HOST_HTTPS_PORT}:443"
1194+
depends_on:
1195+
- php-fpm
1196+
networks:
1197+
- frontend
1198+
- backend
1199+
```
1200+
1201+
1202+
1203+
1204+
11241205
<br>
11251206
<a name="Use-Mosquitto"></a>
11261207
## Use Mosquitto (MQTT Broker)
@@ -1144,7 +1225,6 @@ docker-compose up -d mosquitto
11441225

11451226

11461227

1147-
11481228
<br>
11491229
<a name="CodeIgniter"></a>
11501230

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,24 @@ services:
13311331
aliases:
13321332
- fetchmail
13331333

1334+
### TRAEFIK #########################################
1335+
traefik:
1336+
build:
1337+
context: ./traefik
1338+
command: --docker
1339+
volumes:
1340+
- /var/run/docker.sock:/var/run/docker.sock
1341+
ports:
1342+
- "${TRAEFIK_HOST_HTTP_PORT}:80"
1343+
- "${TRAEFIK_HOST_HTTPS_PORT}:443"
1344+
networks:
1345+
- frontend
1346+
- backend
1347+
labels:
1348+
- traefik.backend=traefik
1349+
- traefik.frontend.rule=Host:monitor.localhost
1350+
- traefik.port=8080
1351+
13341352
### MOSQUITTO Broker #########################################
13351353
mosquitto:
13361354
build:

env-example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,13 @@ MAILU_WEBMAIL=rainloop
623623
# Dav server implementation (value: radicale, none)
624624
MAILU_WEBDAV=radicale
625625

626+
627+
### TRAEFIK #################################################
628+
629+
TRAEFIK_HOST_HTTP_PORT=80
630+
TRAEFIK_HOST_HTTPS_PORT=443
631+
632+
626633
### MOSQUITTO #################################################
627634

628635
MOSQUITTO_PORT=9001

traefik/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM traefik:1.7.5-alpine
2+
3+
LABEL maintainer="Luis Coutinho <luis@luiscoutinho.pt>"
4+
5+
COPY traefik.toml acme.json /
6+
7+
RUN chmod 600 /acme.json

traefik/acme.json

Whitespace-only changes.

traefik/traefik.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
defaultEntryPoints = ["http", "https"]
2+
3+
[entryPoints]
4+
[entryPoints.http]
5+
address = ":80"
6+
[entryPoints.http.redirect]
7+
entryPoint = "https"
8+
[entryPoints.https]
9+
address = ":443"
10+
[entryPoints.https.tls]
11+
12+
[web]
13+
address = ":8080"
14+
[acme]
15+
email = "email@example.org"
16+
storage = "acme.json"
17+
entryPoint = "https"
18+
onHostRule = true
19+
[acme.httpChallenge]
20+
entryPoint = "http"
21+
22+
[[acme.domais]]
23+
main = "localhost"

0 commit comments

Comments
 (0)