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

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?

Categories

HOME
drupal
grizzly
ftp
itunesconnect
netty
primefaces
webvr
apache-storm
nagios
django-middleware
magento-1.9.2.1
itext7
bitbucket
coordinates
msbi
schema
kairosdb
vichuploaderbundle
osclass
minimum
console-application
appsettings
reportlab
filehelpers
ringcentral
alert
project-reactor
legend-properties
hl7-fhir
bootstrap-datetimepicker
computation-theory
ajaxcontroltoolkit
formulas
policy
ithit-webdav-server
knapsack-problem
launchd
custom-fields
spock
boost-log
loopback
availability
flickr
webclient
wunderground
google-cloud-powershell
compiler-warnings
bzip2
mtm
libzip
lucee
dcom
cloudconvert
jcs
intermediate-language
zedgraph
mac-app-store
ldd
visual-web-developer
jspx
virtualenvwrapper
disconnect
geokit
android-xmlpullparser
hotkeys
laterjs
phpdesigner
web-optimization
nugetgallery
trendline
instabug
yfiles
redquerybuilder
jain-sip
dpkt
avrcp
eggplant
cakephp-2.6
waterline
httpmodule
skview
strcpy
conkeror
growl
debuggervisualizer
android-relativelayout
facebook-java-api
starling-framework
php-amqplib
ekevent
http-compression
nsregularexpression
junit-rule
expresso-store
qvariant
linq-to-mysql
hp-trim
pkcs#7
time-management

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