I am currently setting up a system that is composed of different Docker containers that somehow have to communicate with each other.
One Docker container is dedicated to a XMPP server (prosody). This container is started by following docker-compose.yml
:
version: "3.8"
services:
prosody_server:
container_name: prosody_server
build:
context: ./
dockerfile: Dockerfile
ports:
- "5222:5222"
- "5269:5269"
- "5347:5347"
When I run docker ports
on that container, I get following output implying that the mapping of the ports works:
5222/tcp -> 0.0.0.0:5222
5269/tcp -> 0.0.0.0:5269
5347/tcp -> 0.0.0.0:5347
The second Docker container runs a Python script that interacts with the XMPP server and further hosts a simple web interface.
My problem is that the second Docker container for some reason can only communicate with the XMPP server in the first container, if I set network_mode: "host"
in the docker-compose.yml
that starts the Python script:
version: '3.8'
services:
python_script:
build:
context: ../
dockerfile: docker/Dockerfile
container_name: python_script
stdin_open: true
network_mode: 'host'
working_dir: '/python'
command: bash -c 'python main.py'
In this case, I can run the Docker container with the Python script successfully and it is able to communicate with the XMPP server.
However, the web interface is not accessible in that case. It is hosted using the library aiohttp
and serves 0.0.0.0:8080
.
Using the bash of the Docker container serving the Python script, I can successfully request the interface by entering curl localhost:8080
, but it is not accessible from outside the container.
As far as I understood, using network_mode: "host"
would theoretically enable be to use curl localhost:8080
analogously on my host machine, but is does not work.
Changing the network configuration of either the XMPP server's Docker container or the container of the Python script also did not work, as this interferes with the communication between these containers.
I also added exceptions to my firewall and temporally disabled it completely, but this didn't solve the problem.