I am running into an issue with my docker application. On my local network at home, I have a server running on ip address: 192.168.2.10. I wrote a NestJS application which connects to the MQTT server on my server to get some data. This all worked fine, until I containerized my application.
I do understand what’s going wrong, because the docker container is running in an entire different network system, so it can’t access something from outside his network. However, I thought that I could use the bridged network to get this to work, so I have the following config:
services:
service:
build:
context: .
dockerfile: Dockerfile
target: development
volumes:
- ./logs:/usr/src/app/logs
- .:/usr/src/app
environment:
- NODE_ENV=development
networks:
- my-application
networks:
my-application:
driver: bridge
But running this still gives me a connection timeout: Error: connack timeout
, no matter if I put the bridged network or not, I receive the same error. I also tried setting a local DNS that I configured on my router, but the container also can’t reach my router of course.
What am I doing wrong and how can I fix this?