I've been trying to make container to container communication possible by using the treafik router rule I set on a nginx(API) container. I need to do this because of a nuxt application that requires the same API url on the server and client.
I now did this by giving the traefik container an alias that is the same as the router rule of the nginx container, and by adding the node(nuxt) container to the same network as the traefik container.
But is there a better way? My solution feels.. dirty..
services:
# Proxy
traefik:
image: traefik:v2.4.5
command:
- --api.insecure=true
- --providers.docker
- --providers.docker.exposedByDefault=false
- --entryPoints.websecure.address=:443
- --entryPoints.web.address=:80
- --providers.file.directory=/configuration
- --providers.file.watch=true
ports:
- 80:80
- 443:443
- 8080:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock:cached
- ./docker/traefik/traefik.toml:/configuration/traefik.toml
- ./docker/traefik/certs/:/etc/certs/
networks:
proxy:
aliases:
- ${API_DNS}
# API
nginx:
build:
context: ./api
dockerfile: ./docker/nginx/Dockerfile.dev
volumes:
- ./api/public:/app/public
networks:
- proxy
- api
labels:
- traefik.http.routers.api.entrypoints=websecure
- traefik.http.routers.api.tls=true
- traefik.http.routers.api.rule=Host(`${API_DNS}`)
- traefik.enable=true
- traefik.docker.network=proxy
.......
# client
client:
build:
context: ./client
dockerfile: ./docker/node/Dockerfile.dev
volumes:
- ./client:/app
ports:
- 3000:3000
networks:
- proxy