-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feature/implement traefik documentation #628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,122 @@ | ||||||
# Implement Traefik into API Platform dockerized | ||||||
|
||||||
## Basic implementation | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
[Traefik](https://traefik.io) is a reverse proxy / load balancer that's easy, dynamic, automatic, fast, full-featured, open source, production proven, providing metrics, and integrating with every major cluster technologie | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technology |
||||||
|
||||||
This tool will help you to define your own routes for your client, api and more generally for your containers. | ||||||
|
||||||
Use this custom API Platform docker-compose.yml file which implements ready-to-use Traefik container configuration. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Override ports and add labels to tell Traefik to listen the routes mentionned and redirect routes to specified container. | ||||||
|
||||||
|
||||||
```--api``` Tell Traefik to generate a browser view to watch containers and IP/DNS associated easier | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
```--docker``` Tell Traefik to listen docker api | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
```--docker.domain=localhost``` The main DNS will be on localhost | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
```labels:``` Key for Traefik configuration into Docker integration | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
services: | ||||||
... | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
api: | ||||||
labels: | ||||||
- "traefik.frontend.rule=Host:api.localhost" | ||||||
``` | ||||||
The api DNS will be specified with traefik.frontend.rule=Host:your.host (here api.localhost) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```--traefik.port=3000``` Port specified to Traefik will be exopsed by container (here React app expose the 3000 port) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
```yaml | ||||||
version: '3.4' | ||||||
|
||||||
services: | ||||||
reverse-proxy: | ||||||
image: traefik | ||||||
command: --api --docker --docker.domain=localhost | ||||||
ports: | ||||||
- "80:80" #All HTTP access will be caught by Traefik | ||||||
- "8080:8080" #Access Traefik webview | ||||||
volumes: | ||||||
- /var/run/docker.sock:/var/run/docker.sock | ||||||
|
||||||
php: | ||||||
image: ${CONTAINER_REGISTRY_BASE}/php | ||||||
build: | ||||||
context: ./api | ||||||
depends_on: | ||||||
- db | ||||||
env_file: | ||||||
- ./api/.env | ||||||
Comment out these volumes in production | ||||||
volumes: | ||||||
- ./api:/srv/api:rw,cached | ||||||
If you develop on Linux, uncomment the following line to use a bind-mounted host directory instead | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- ./api/var:/srv/api/var:rw | ||||||
|
||||||
api: | ||||||
image: ${CONTAINER_REGISTRY_BASE}/nginx | ||||||
labels: | ||||||
- "traefik.frontend.rule=Host:api.localhost" | ||||||
build: | ||||||
context: ./api | ||||||
depends_on: | ||||||
- php | ||||||
Comment out this volume in production | ||||||
volumes: | ||||||
- ./api/public:/srv/api/public:ro | ||||||
|
||||||
db: | ||||||
In production, you may want to use a managed database service | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for all other comments of this file |
||||||
image: postgres:9.6-alpine | ||||||
labels: | ||||||
- "traefik.frontend.rule=Host:db.localhost" | ||||||
environment: | ||||||
- POSTGRES_DB=api | ||||||
- POSTGRES_USER=api-platform | ||||||
You should definitely change the password in production | ||||||
- POSTGRES_PASSWORD=!ChangeMe! | ||||||
volumes: | ||||||
- db-data:/var/lib/postgresql/data:rw | ||||||
You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data! | ||||||
- ./docker/db/data:/var/lib/postgresql/data:rw | ||||||
ports: | ||||||
- "5432:5432" | ||||||
|
||||||
client: | ||||||
Use a static website hosting service in production | ||||||
See https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.mddeployment | ||||||
image: ${CONTAINER_REGISTRY_BASE}/client | ||||||
build: | ||||||
context: ./client | ||||||
env_file: | ||||||
- ./client/.env | ||||||
volumes: | ||||||
- ./client:/usr/src/client:rw,cached | ||||||
- /usr/src/client/node_modules | ||||||
expose: | ||||||
- 3000 | ||||||
labels: | ||||||
- "traefik.port=3000" | ||||||
- "traefik.frontend.rule=Host:localhost" | ||||||
|
||||||
volumes: | ||||||
db-data: {} | ||||||
``` | ||||||
|
||||||
Don't forget the db-data, then database won't work in this dockerized solution. | ||||||
|
||||||
```localhost``` is a reserved domain referred in your ```/etc/hosts```. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
If you want to implement custom DNS such as production DNS in local, just put them at the end of your ```/etc/host``` file like that : | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
``` | ||||||
# /etc/hosts | ||||||
... | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
127.0.0.1 your.domain.com | ||||||
``` | ||||||
|
||||||
If you do that, you'll have to update the nelmio part in your```api/.env``` and accept the URL specified | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## Known problems | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Take care of your network, if it's a type B network it may not work because containers are in type B network and it will be in conflict with Traefik sub-network | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.