Docker compose: using relative service address in environment
For example, I defined two services in my docker-compose backend: env_file: - .env.backend build: context: . dockerfile: Dockerfile ports: - "8686:8686" frontend: env_file: - .env.front_end build: context: . dockerfile: Dockerfile ports: - "3000:3000" In frontend app, I defined environment with this endpoint: BACKEND_ENDPOINT=http://www.backend.com/api/v1/backend/ The problem I don't know how to solve here is: how can I convert above endpoint to relative endpoint based on backend service. For example, if you run only backend under localhost, url should be: localhost:8686/api/v1/backend. So the url of backend in above docker-compose file should be: [backend_address]:8686/api/v1/backend. So how can I map address and port automatically here. Thanks
With docker-compose, all services are always resolvable by their names. In your example, you should add a depends_on from your frontend to your backend, and simply use the name backend to address the backend server. frontend: depends_on: - 'backend' The frontend should be able to resolve the backend at backend:8086. Note that the depends_on isn't required for name resolution, but it is required to ensure that the port is open when your frontend container is created.
Name an image built from running a docker-compose file
Race conditions after changing names in docker-compose.yml
Docker compose - image not found
How to work out the hostname that compose gives containers?
docker-compose restart container if service is dead
Swarm scheduling not working as expected using filters in compose file
issues in buiding Slate with Docker
Invalid type error in Docker Compose
Django cookiecutter with Docker add pip package
Docker Compose + Swarm + Machine Networking issue
docker-compose build image parameters --force-rm --pull
linking 2 containers through docker compose
Files created by manage.py commands not chown'd from root user
Is it possible to create an intermediate image within docker-compose?
docker-compose service listen on specified interface
Does Docker-Compose allow overwriting of ports when using extends?