-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development question: How to make MQTT work inside the docker container #117
Comments
Hi @nexysm , not sure I understand correctly. Do you want to receive/send messages to/from the mosquitto message broker from your host machine? If so you would need to forward the mqtt port from inside the container network to your host. It would be done the same way as it is already done for the craftbeerpi web ui and the mqtt explorer in "forwardPorts": [
"craftbeerpi4-development:8000",
"mqtt-explorer:4000",
"mqtt:1883" // <-- Add this to forward 1883 port from the mqtt container
], After that (and restarting the dev environment) you should be able to access the message broker from your host machine. |
@papauorg Thanks for the answer, I almost lost my hope. I will try this immediately. Meanwhile I tried to understand the whole concept, still doing that, but since I lack the basic understanding of the Docker thing, I would like to ask an additional question. Why is this what you suggested going to work? I ask this because the following reason: |
I'm sure it will become clearer as you get familiar with the overall concept. It is more difficult here, as there are multiple concepts at work. There is docker, docker-compose and devcontainers here. When using the dev-environment you are using several docker containers. Those containers are located in a virtual network and are not accessible from your host machine. If you want to access them from your host, which is in another network, you need to forward the ports of your containers to your host (-network). If you already have a message broker on your host, that is using the same port, then forwarding the default port will not work as it is already taken. At least if only docker and docker-compose would be involved. I'm not entirely sure, but it may be possible that vscode automatically reassigns the host port to a free one if the same port is already taken. You can see that in the "Ports" tab in vscode after you start the dev environment: |
@papauorg thanks! It worked. It also works when using a broker on the host machine with adding the extra hosts in the docker-compose.dev.yml:
In which case the configuration should be like this:
|
Hi all guys,
I am struggling to get MQTT messages when running the development environment from the VScode. COuld you please tell me how to proceed with this? I tried several things, one among them using socat and trying to relay the traffic there but without success. I am at the end hardware engineer :).
Thank you
The text was updated successfully, but these errors were encountered: