Use Docker networks to share the same localhost

Docker

Use Docker networks to share the same localhost between containers.

In docker-compose.yml file:

yaml

version: "3.7" services: backend: ... ports: - "8000:8000" expose: - "8000" networks: - dev frontend: ... ports: - "3000:3000" networks: - dev networks: dev: driver: bridge

Since both backend and frontend containers are on the same network, you can now access localhost:8000 from the frontend container.