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

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
dynamic link update in docker-compose
How to start arbitrarily many identical containers with docker-compose?

Categories

HOME
reactjs
excel-formula
repository
kendo-ui
postgresql-9.3
customization
gap-system
skypedeveloper
highmaps
squeak
checkpoint
foreach
servicenow
kendo-asp.net-mvc
open-search-server
annyang
token
jpql
angular-universal
http-status-codes
jetbrains
hdf5
mbed
webseal
hql
loss
facebook-marketing-api
amazon-data-pipeline
reportlab
geography
hapijs
project-reactor
sonarlint
single-page-application
vala
dev-c++
rndis
google-drive-android-api
struts
scrapy-spider
jira-zephyr
datanucleus
inspec
multiple-inheritance
emr
federated
jbossfuse
key-bindings
jcr
fastadapter
odp.net
cache-control
kofax
jibx
mixed-models
pyexcel
uitextview
wufoo
amazon-fire-tv
ack
spring-webflow-2
react.rb
multivalue
jcifs
webmatrix
liferay-ide
grib
suitesparse
portaudio
toggleclass
magick.net
normalisation
angularfire
weblogic-maven-plugin
diameter-protocol
aws-kms
factorization
web-performance
ios8-share-extension
biginsights
exchange-server-2007
textblob
android-filterable
eaaccessory
playn
page-refresh
glog
mergecursor
screen-lock
wingdb
douglas-peucker
optimistic-locking
nsq
unityvs
telerik-appbuilder
banana-pi
email-headers
power-management
connections
complete
surfaceview
tlbimp
zend-db-table
leap-year
http-compression
wordbreaker
junction-table
reference-manual
m3u
jquery-1.8
nude.js
funambol
object-tag
moss2007-security
rollover
nscharacterset
retrospectiva
content-delivery-network
moores-law

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