There’s quite a bit of tedious work involved to accomplish this, and you’d really have to weigh the effort carefully against how hard it would be to set up some kind of DNS instead. However, if you really must use port numbers, here are some places to start. This isn’t an exhaustive guide, and you should proceed only at your own risk. I might not be able to help again for weeks or months if you get stuck, although others in the community may be able to give assistance. There are no guarantees.
You would not have to worry about the ports that each application listens on, but you would have to change the NGINX configuration and then configure the applications to communicate with each other by port number instead of hostname. Let’s use this example:
$ docker ps
CONTAINER ID <snip> PORTS NAMES
05e709982b7a <snip> 0.0.0.0:80->80/tcp kobofe_nginx_1
1dac2d1fc448 <snip> 8000/tcp kobofe_kpi_1
f76c4ebed1f3 <snip> 8000-8001/tcp kobofe_kobocat_1
8cc92847a458 <snip> 8005/tcp kobofe_enketo_express_1
4fb977f49306 <snip> 6379/tcp kobobe_redis_cache_1
bce62dd536a7 <snip> 5432/tcp kobobe_postgres_1
a06c464d189a <snip> 27017/tcp kobobe_mongo_1
34cadeccbbfa <snip> 6379/tcp kobobe_redis_main_1
Assuming that the IP of my host here is 10.1.2.3, I would usually have three hostnames pointing to that address:
- kf.my.host → 10.1.2.3
- kc.my.host → 10.1.2.3
- ee.my.host → 10.1.2.3
NGINX would receive requests for all three on port 80, and the proxy_pass
directive would tell it how to route traffic based on the HTTP Host
header:
- kf.my.host → port 8000 of the KPI container,
- kc.my.host → port 8001 of the KoBoCAT container,
- ee.my.host → port 8005 of the Enketo container.
All of those application ports can stay the same, but to avoid using hostnames, you’d have to make NGINX listen on three ports instead of one. Let’s say you picked 81, 82, and 83. You’d then change the three server
blocks (for KPI, KoBoCAT, and Enketo) in the NGINX configuration to listen
on ports 81, 82, and 83, respectively, instead of having them all set to 80. That would let you stop relying on server_name
to route the traffic. See this configuration template.
You would also have to configure Docker to publish ports 81, 82, and 83 of the NGINX container instead of just 80. See ports
in this example Docker Compose configuration override file.
Finally, you would have to tell the applications how to communicate with each other via ports instead of hostnames. We haven’t tested this in a long time, but you should be able to do it by hard-coding KOBOFORM_URL
, KOBOCAT_URL
, ENKETO_URL
, and all the …INTERNAL_URL
environment variables. Here’s one file that you would have to change, but it’s not the only one.