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.
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?
Jhipster Docker-compose conflict
Build multiple images with Docker Compose?
JHipster Cassandra Docker Build
Defining project name inside docker-compose configuration
Docker-compose named mounted volume
cannot ping linked docker container service
How to do variable substitution in env_file?
How to create stack in tutum with docker-compose.yml file?
ecs-cli docker compose version