Hi,
First, thank you just for reading this and trying to help us.
We are migrating from v1 to v2 and have some issues on API calls from back to back.
We used to have 2 networks (front and back), and our backend used to communicate via back network using aliases.
With v2, we struggle to understand how to do it.
The context :
- VueJs Front that calls our php API (works well)
- VueJs Front calls php WS (works well)
- php WS that calls php API (doesn't work)
Here are the interesting sample of our docker-compose files
Traefik
version: "3"
services:
traefik:
env_file: ./.env
container_name: app-traefik
image: ${TRAEFIK_IMAGE}
command:
- "--log.level=DEBUG"
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
ports:
- 8181:8080
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- "proxy"
networks:
proxy:
WS
version: "3"
services:
php:
env_file: ./.env
image: app/ws/php
container_name: app-ws-php
build: ./.docker/ws/local
volumes:
- ./:/var/www
labels:
traefik.enable: true
traefik.http.routers.websocket.rule: Host(`ws.${URL}`)
traefik.http.routers.websocket.entrypoints: web
traefik.http.routers.websocket.service: websocket
traefik.http.services.websocket.loadbalancer.server.port: ws.${URL}
traefik.http.services.websocket.loadbalancer.server.port: 8080
providers.docker.network: proxy
networks:
- proxy
networks:
proxy:
external:
name: "traefik_proxy"
API
version: "3"
services:
nginx:
env_file: ./.env
image: app/api/nginx
container_name: app-api-nginx
build: ./.docker/nginx/local
volumes:
- ./:/var/www
labels:
traefik.enable: true
traefik.http.routers.api.rule: Host(`api.${URL}`)
traefik.http.routers.api.entrypoints: web
traefik.http.routers.api.service: api
traefik.http.services.api.loadbalancer.server.url: api.${URL}
traefik.http.services.api.loadbalancer.server.port: 80
providers.docker.network: proxy
environment:
NGINX_PORT: 80
depends_on:
- php
- db
networks:
- proxy
php:
env_file: ./.env
image: app/api/php
container_name: app-api-php
build: ./.docker/php/local
volumes:
- ./:/var/www
depends_on:
- db
labels:
traefik.enable: false
networks:
- proxy
db:
env_file: ./.env
image: mysql:8.0.19
container_name: app-api-db
environment:
- MYSQL_DATABASE=app
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=app
- MYSQL_PASSWORD=app
volumes:
- app-api-db:/var/lib/mysql:cached
ports:
- 3311:3306
networks:
- proxy
volumes:
app-api-db:
networks:
proxy:
external:
name: "traefik_proxy"
Here is our WS logs when trying to call API :
cURL error 6: Could not resolve host: api.dev.app.com
It works well if I use the container_name since they are on the same network (proxy), but I can't find how to set a backend URL (from back to back).
If anyone can enlight me.
Thanks in advance to anyone who have read that
Have a nice day,