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 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

Categories

HOME
gcc
salesforce
intellisense
popover
file-upload
azure-database-mysql
crm
azure-resource-manager
itext7
coordinates
mingw
yuv
procmon
country-codes
clip-path
vsixmanifest
phpexcel
rename
wowza
google-search-appliance
web-worker
alert
dev-c++
matlab-gui
pumping-lemma
gsuite
ckeditor4.x
windows-mobile
symlink
utc
semantic-ui-react
deferred
intermec
exacttarget
cache-control
android-databinding
rythm
yelp
fisheye
aura-framework
mtm
binary-decision-diagram
pexpect
smooth-streaming
nshttpurlresponse
ocamlbuild
serverless-architecture
jsfl
seyren
cc
multi-select
spring-cloud-aws
stripes
computed-properties
gevent
firebase-job-dispatcher
indoor-positioning-system
init
angularfire
cascading
kramdown
mojolicious
uinavigationitem
cyberduck
tess4j
hexagonal-tiles
firebase-tools
service-broker
dockerpy
selenium-grid2
nsmutableurlrequest
php-amqplib
adabas
ekevent
friendly-id
violation
xrandr
architectural-patterns
ios6-maps
beep
flatten
cherokee
funambol
hwnd
azure-appfabric
xcdatamodel
arraycollection
qprocess
versions
pixel-bender
content-delivery-network

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