docker-compose


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.

Related Links

docker copy container data to volume using compose
Docker-compose ps error
hyperledger-fabric getting-started failed to start cli container
how to make docker-compose pull latest images of certain services
network issue in one docker compose with keycloak and tomcat container
Docker compose, set local volume mapping with version 3
version control of docker-compose.yml
Limit resources in docker-compose v3
Docker compose: using relative service address in environment
Azure Container Service: Update Docker-Compose?
Docker compose: doesnt allow to use constraints if you have a env variable set
How to use visual studio docker function on Windows Home edition?
Passing arguments to docker compose file when using it for swarm
How to run ad hoc docker compose commands in Ansible?
Using custom hostnames for docker local development containers
Changing the network name?

Categories

HOME
drupal
classification
youtube-api
javafx
optimization
mobile
ssh
customization
snappy
windows-server-2008
azure-resource-manager
arguments
opc-ua
artifactory
opacity
travis-ci-cli
webpack-dev-server
box-api
coding-style
elastalert
dynamics-crm-2011
aspectj
eclipse-orion
hql
jquery-easyui
git-branch
mattermost
infinite-loop
android-wear-2.0
sasl
cloudformation
typeclass
git-submodules
osgi-bundle
spring-oauth2
wercker
oracle-nosql
jsonapi-resources
ilog
gstreamer-1.0
anypoint-studio
pygraphviz
byobu
lfe
azure-web-roles
flume-ng
taiga
nshttpurlresponse
encoder
mef
react.rb
hdpi
nao-robot
beanshell
seyren
multi-select
esprima
google-scholar
mac-app-store
networkstream
disconnect
queuing
avi
factorization
android-contentresolver
producer-consumer
windows-phone-8-emulator
autoscaling
tooltwist
vspackage
page-refresh
system.diagnostics
douglas-peucker
launcher
mind-manager
growl
nsnotificationcenter
time-frequency
mvcgrid
behance-api
pthreads-win32
mongoid4
flask-mongoengine
boofcv
complete
scidb
openafs
expresso-store
webpage-screenshot
bindinglist
mcpd
session-hijacking
backlight
funambol
linq-to-mysql

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App