docker-compose


Let external container know about subnets created by multiple docker-compose projects


I have a multi-client setup, each client having similar application stack. To simplify it a bit, let's say a typical tomcat web app working on a db.
Clients must be completely isolated from each other, each with their on application stack, including a standalone tomcat).
VirtualHost configurations on httpd map domains to the corresponding tomcat instance via AJP.
For example:
client1.example.com -> 172.18.0.2:8009
client2.example.com -> 172.19.0.2:8009
I found docker-compose very useful within each client. One of the things I like is that it even takes care of creating private subnets for each client and containers within that client don't even need to know other containers' IP address, but can use aliases that are automatically set up by the links configuration. Pretty neat.
httpd
clients
client1
docker-compose.yml
tomcat
db
client2
docker-compose.yml
tomcat
db
Now the problem. httpd (which I would also want to dockerize) needs to reach tomcat for all clients. However, it doesn't know their IP.
How can I realize this mapping in VirtualHost? I.e. how to solve the question marks below?
<VirtualHost *:443>
ServerName client1.example.com
..
ProxyPass / ajp://?????:8009/
..
</VirtualHost>
One thing I have tried is to have some global env file, with all subnets and IPs explicit, like:
CLIENT1_TOMCAT=172.18.0.2
CLIENT2_TOMCAT=172.19.0.2
and use this in both each client's yml and httpd yml.
That's pretty ugly though, because custom IP configuration within a yml is either for all or for no service. I was hoping I could set the one for tomcat and let the others automatic, but they end up overlapping. All the sudden, specifying IP configurations for all services and all clients, makes the whole thing a lot less elegant.
I also know it is possible to inspect a container's IP like this:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' client1_tomcat
However, this requires the container to exist already. Also, if I use this method then I have to modify httpd's configuration every time the container is recreated, as it may change IPs.
I guess that somehow I wold like httpd's yml to "include" the clients' ones, so that it can know about their subnets. Still, keeping clients' subnets separated.
Any idea how I should approach this?
UPDATE
working setup based on #tcnj's answer:
Content of httpd/docker-compose.yml:
version: '2'
services:
httpd:
image: httpd
ports:
- "80:80"
..
networks:
- client1_default
- client2_default
external_links:
- client1_tomcat_1
- client2_tomcat_1
networks:
client1_default:
external: true
client2_default:
external: true
The easiest way to solve your problem is to put httpd on all of the client networks, and then refer to the tomcat containers by their name.
Eg:
You have client1 with network client1_default, and with the container client1_tomcat.
You also have client2 with network client2_default, and with the container client2_tomcat.
If you're starting httpd from the command line then you can add --network client1_default --network client2_default as extra options to docker run before the image name. If you're using docker compose for httpd as well then you can use the following:
httpd:
...
networks:
- client1_default
- client2_default
...
In your httpd config you can then have:
<VirtualHost *:443>
ServerName client1.example.com
...
ProxyPass / ajp://client1_tomcat:8009/
...
</VirtualHost>
<VirtualHost *:443>
ServerName client2.example.com
...
ProxyPass / ajp://client2_tomcat:8009/
...
</VirtualHost>

Related Links

What is the version directive for?
How to run docker-compose up -d at system start up?
In Docker Compose can I have services exiting
Docker compose - secrets Additional property secrets is not allowed
docker-compose mounted volume remain
Should I do anything after upgrading docker-compose?
docker caddy proxy not forwarding
docker share OS volume between services
How dynamic map service name to ENV var
docker-compose v3 services on several networks
URL for cloudant on docker compose
Apache Metron Docker Compose Start Up Error
Apache Metron Docker Compose Start Up Error (Repost)
How to only restart one service in docker
Docker gem therubyracer error installation in ruby container
Error using docker-compose down

Categories

HOME
excel-formula
ssms
botframework
intellij-idea
process
spss
lithium
thermal-printer
confluence-rest-api
perl6
angularjs-directive
schema
restheart
revit-api
promotions
ionic-native
desktop-application
derby
console-application
jsfiddle
openscad
computation-theory
keystone
jq
datastax-enterprise
inspec
traveling-salesman
pydub
dynamics-ax-2012-r3
vtd-xml
slim-lang
instances
web-technologies
runner
google-cloud-shell
ear
aws-rds
kendo-scheduler
spring-cloud-aws
pyautogui
therubyracer
dimensionality-reduction
normalisation
gdi
weblogic-maven-plugin
bluetooth-lowenergy-4.2
app-data
controlpanel
producer-consumer
random-sample
first-order-logic
jsoncpp
grails-3.0.9
perfect-scrollbar
xmla
alpha-beta-pruning
qf-test
azure-worker-roles
fscanf
pidgin
pthreads-win32
flask-mongoengine
ie-developer-tools
cab
zend-db-table
dd4t
removeall
exi
msbuild-task
auctex
system.transactions
dnsbl
inflate
php-gettext
pdf-reader
youtube.net-api
html5-animation
onunload
fxcopcmd
xcdatamodel
qprocess
calendarextender
datadude
ihtmldocument2
cons

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