Added networking example
This commit is contained in:
parent
18d66d7432
commit
af71443b61
2 changed files with 35 additions and 1 deletions
|
@ -50,7 +50,12 @@ Now that we have a Traefik instance up and running, we will deploy new services.
|
||||||
Edit your `docker-compose.yml` file and add the following at the end of your file.
|
Edit your `docker-compose.yml` file and add the following at the end of your file.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# ...
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
whoami:
|
whoami:
|
||||||
# A container that exposes an API to show its IP address
|
# A container that exposes an API to show its IP address
|
||||||
image: traefik/whoami
|
image: traefik/whoami
|
||||||
|
|
|
@ -16,6 +16,35 @@ This will also be used as a starting point for the other docker-compose guides.
|
||||||
--8<-- "content/user-guides/docker-compose/basic-example/docker-compose.yml"
|
--8<-- "content/user-guides/docker-compose/basic-example/docker-compose.yml"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
??? Networking
|
||||||
|
|
||||||
|
The Traefik container has to be attached to the same network as the containers to be exposed.
|
||||||
|
If no networks are specified in the docker-compose file, Docker creates a default one that allows Traefik to reach the containers defined in the same file.
|
||||||
|
You can [customize the network](https://docs.docker.com/compose/networking/#specify-custom-networks) as described in the example below.
|
||||||
|
You can use a [pre-existing network](https://docs.docker.com/compose/networking/#use-a-pre-existing-network) too.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: "3.3"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
traefiknet: {}
|
||||||
|
|
||||||
|
services:
|
||||||
|
|
||||||
|
traefik:
|
||||||
|
image: "traefik:v2.9"
|
||||||
|
...
|
||||||
|
networks:
|
||||||
|
- traefiknet
|
||||||
|
|
||||||
|
whoami:
|
||||||
|
image: "traefik/whoami"
|
||||||
|
...
|
||||||
|
networks:
|
||||||
|
- traefiknet
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
- Replace `whoami.localhost` by your **own domain** within the `traefik.http.routers.whoami.rule` label of the `whoami` service.
|
- Replace `whoami.localhost` by your **own domain** within the `traefik.http.routers.whoami.rule` label of the `whoami` service.
|
||||||
- Run `docker-compose up -d` within the folder where you created the previous file.
|
- Run `docker-compose up -d` within the folder where you created the previous file.
|
||||||
- Wait a bit and visit `http://your_own_domain` to confirm everything went fine.
|
- Wait a bit and visit `http://your_own_domain` to confirm everything went fine.
|
||||||
|
|
Loading…
Reference in a new issue