WiFi-connect installation in Raspberry Pi Docker container

Hello @vipulgupta2048

I just tested with the updated docker-compose.yml file, but I got another error. I attached full docker-compose.yml file and error.

version: '2.1'

  maria_data: {}
  grafana_data: {}

    image: jsurf/rpi-mariadb
      - maria_data:/var/lib/mysql/data
      - ./mysql-dump:/docker-entrypoint-initdb.d
      - PUID=1000
      - PGID=1000
      - TZ=Etc/UTC
      - MYSQL_ROOT_PASSWORD=admin12345
      - MYSQL_DATABASE=dtects_db
      - MYSQL_USER=admin
      - MYSQL_PASSWORD=admin12345
      - 3306:3306
    restart: unless-stopped

       context: .
       dockerfile: ./compose/django/Dockerfile-dev
     network_mode: "host"
     privileged: true
       - ./:/app/
       - /run/dbus/system_bus_socket:/host/run/dbus/system_bus_socket
       - db
     restart: always
       - "8000:8000"
       - "/dev/ttyAMA0:/dev/ttyAMA0"
       - NET_ADMIN
       - DBUS_SYSTEM_BUS_ADDRESS="unix:path=/host/run/dbus/system_bus_socket"

    image: grafana/grafana:latest
      - grafana_data:/var/lib/grafana:rw
      - ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
      - ./grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards
      - ./grafana/dashboards:/var/lib/grafana/dashboards
      - ./grafana/plugins:/var/lib/grafana/plugins
     - "3000:3000"
   restart: unless-stopped
     - db

Here is the error at the end of building.


The error means that you need to remove the ports definition from your django container.

       - "8000:8000"

You do not have to expose ports like this as the host network mode already attaches all ports to the host network namespace.

That’s a serious problem.
If I remove the port option from django service, is it possible to access to web page(django server)?
If it’s possible, can I still use 8000 port?

Hi @majorz @vipulgupta2048

I executed wifi-connect successfully in Django container by removing the ports option from docker-compose.yml file as you suggested. Instead, I can’t connect to my Django server via 8000 port.
How can I access Django server? Or is it impossible? This is not what I wanted.
Looking forward to your good solution.


Hi Anatoli. network_mode: host means that all ports that specific service listens to are already accessible to the outside, so that’s why it is not necessary to manually specify the ports.

If the django container is running but not accessible on port 8000, it means that django is not listening on port 8000. Could you check that the server process is actually running and that it is configured to listen on port 8000?

Hi Balena members!

I executed wifi-connect successfully in django container. Also, django server is running on 8000 port.
Thanks for your great help

However, I still have a serious problem on using wifi-connect in the container.
When I run this app again after connecting the pi to one of the nearby networks using wifi-connect, I see only the last connected network in the wifi network list of the balena app.
Even sometimes, when I tried to connect the original Network again, it first succeeds and then goes back to the AP.

I also tried wifi-connect outside the container(on hostOS), but the result was the same.
Very weird. What do you think about that?


Hi Antoli

Can you share logs of when this happens? You should be able to get them using journalctl -u NetworkManager on your Raspbian.

Hi @anujdeshpande

I repeated the test several times to report the exact situation to you.
I have attached a screenshot showing the activity of the balena app running on my phone.

As you can see, I initially connected the Pi to Almond3d21 Network. It worked well.
And then I tried to change the Network to TP-LINK-REAL3D, but it failed. As you can see, when I tried to connect Pi to TP-LINK-REAL3D, it disappeared in AP list. The Pi goes to AP mode again.
When I close balena app on my phone and re-open, I see only Almond3d21 AP in Network List.
I don’t see TP-LINK-REAL3D AP.
When I tried to reconnect to Almond3d21 Network, then it works.

The above process does not happen occasionally. It is completely regular. In other words, Pi can be only reconnect to the network it was initially connected to, not to other networks.
Also, I can only see the network that was initially connected in AP list.
I also tested wifi-connect outside the container(hostOS). The result was the same.
What’s the reason?

For reference, I installed wifi-connect on hostOS with the following command.

bash <(curl -L https://github.com/balena-io/wifi-connect/raw/master/scripts/raspbian-install.sh)

And I installed wifi-connect inside my django container with the following commands

RUN apt-get update && apt-get install -yq --no-install-recommends
dnsmasq &&
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN curl https://api.github.com/repos/balena-io/wifi-connect/releases/latest -s
| grep -hoP ‘browser_download_url": "\K.*armv7hf.tar.gz’
| xargs -n1 curl -Ls
| tar -xvz -C /app/

NetworkManager has been installed only on hostOS, not in the container. Therefore, only when wifi-connect is installed in host os, wifi-connect runs without error inside the container.

I will attach NetowrkManager logs on the following thread because I can’t attach more two screenshot on a thread.

Hi @anujdeshpande

Here are the logs of NetworkManager. I just attached the latest 60 lines.
I hope it will help you to solve this problem.

Thanks in advance.

Hi @anujdeshpande @vipulgupta2048
I hope you’re doing well.
Did you have a chance to look at my last issue? I attached my situation in detail at Anuj’s request.
I think I’m getting close, but the last issue is embarrassing me.
I hope you suggest a good solution on it.

Hey again Anatoli!

I see you’re still sticking with the problem, good for you. Well, I just read through the ticket and caught up, it looks like the network manager is functioning as intended.

Unless I’m reading it wrong, the network manager looks for the strongest WiFi signal and connects to that signal. This is what people usually want. Even if you have multiple networks available, you are going to want to connect to the strongest signal.

Just to be sure though, can you try disconnecting the original router you connected and seeing if your pi then connects to the other router you saved the credentials for?


Hi @zwhitchcox

I’m very glad to hear from you again.
I was thinking it’s possible to change the WiFi network anytime regardless the strength of WiFi networks using balena wifi-connect app.
That’s why I wanted to use it for my application. However, as I mentioned above, I can’t change the current wifi network to the others. When I tried to connect to another network, the Pi goes back to AP mode. Even, the other networks disappear in Balena AP list and I can only reconnect to the network that I first connected to.

Just to be sure though, can you try disconnecting the original router you connected and seeing if your pi then connects to the other router you saved the credentials for?

I’m not sure how can I disconnect the original router. Did you mean the disconnecting by powering off the original router? The current wifi network has been established by using balena app, not by using wpa_supplicant.conf. There is no any credential files I copied on the Pi manually. Is there a good way to disconnect the original router without powering off?

Without powering off the original router, I made wpa_supplicant.conf for a new wifi network and copied it to /etc/wpa_supplicant folder.
After that, I executed wifi-connect and tried to change the wifi network to the new network. But I can’t still see the new network in balena app. There is only the original router in AP list.
Is this the normal behavior of the balena app?

My ultimate goal is to change the wifi network I want to connect to at anytime using Balena app.
So I need to see all of the networks (they have enough strength) anytime in Balena app and connect to any Network regardless the strength. Does it make sense?


Ahh, ok, I see. Well, then maybe we need to wait to hear from one of the maintainers, @majorz

Hey Zane,
Thanks for your reply. If the WiFi connects to the strongest signal by design, why does the Balena app show all the networks the first time.
I really expect them to come up with a positive solution to realize my final goal.

Hi @zwhitchcox

I hope you’re doing well. I’m still waiting for your solution for my last problem.
What I want to say is that I found out a way to deactivate and delete the wifi connection without powering off the router.
However, I haven’t achieved my ultimate goal yet.
As I said again, my ultimate goal is to change the wifi network I want to connect to at anytime using Balena app. So I need to see all of the networks (they have enough strength) anytime in Balena app and connect to any Network regardless the strength.

Looking forward to hearing a good solution soon.

hi @anatoli - balena-wifi-connect is meant to help fleet owners figure out how to allow end-users to configure wifi credentials easily when a device is installed in a venue. It is open-source so that people can file issues, contribute with PRs or feedback and use it as an example for developing something more custom. I believe your use case (a wifi manager GUI) is beyond the scope of wifi-connect, so I suggest you look at how wifi-connect interacts with the host network-manager and implement your own business logic. It comes down to consuming network-manager’s DBUS API

one thing that could be suggested to the wifi-connect maintainer ( @majorz ) is to allow wifi-connect to be run without the AP mode part (maybe via a command line argument?), so that it just exposes an interface for scanning and setting wifi networks instead.

Thanks for your reply.

I’d like to ask two questions.

Is that mean that it’s necessary to install Balena OS as host OS to use wifi-connect in the container?
2. My host os is raspbian and I have already executed wifi-connect in a web container.
However, I can only reconnect to the network I first connected to through WiFi connect.
Is this because my host OS is raspbian, not balena OS? Or is it the normal operation of wifi connect?

Hey again Anatoli!

Sorry, but it looks it doesn’t matter what OS you’re using, the wifi-connect tool just wasn’t meant to reconnect to different wifi networks after it’s already connected to one.

But here’s the good news: You are pretty much 90% of the way there anyway with your docker container.

wifi-connect is just an interface between you and the network manager…all it’s doing is telling the network manager what to do. And you’ve sort of “outgrown” wifi-connect, because what you’re trying to do isn’t supported by the wifi-connect interface.

But you can take your same container and now just interact with the network manager.

I do believe you’ll have to bind mount the /var/run/dbus though, so in your docker compose file:

        - /var/run/dbus:/var/run/dbus

but everything else should be the same…and then you can just use a tool like nmcli instead of wifi-connect, as that is what the tool is built to do…hopefully this will help you on your way. Unfortunately, we probably can’t provide support for the nmcli tool, but it looks like there should be a pretty straightforward path from here…good luck!

Hi Zane,
Thanks for your reply.

I have another question. How can I use iwgetid command in a docker container?
I was able to use ifconfig command by installing net-tools in the container, but I still couldn’t use iwconfig or iwgetid command.
Is there any solution for it?