Installation Balena wifi-connect on Docker Container

Hi Balean Support team,

I’m struggling with installing Balena wifi-connect inside Django container running on Raspberry Pi.
I downloaded the following git repository on Raspberry Pi4.

This works well outside the docker container, but I want to install and run it inside the web docker container. I don’t want to have it that works as an container. I just want to install and use it in a web container that is already running. I burnt the latest version of RaspbianOS (32bit lite version) on Pi.
Here is Dockerfile for django container.

FROM python:3.7.3
ENV PYTHONUNBUFFERED=0
WORKDIR /app
ADD requirements.txt /app/
RUN pip3 install -r requirements.txt
RUN pip3 install netifaces

RUN apt-get install -y systemd
RUN apt-get install -y supervisor
RUN service supervisor restart

COPY . /app
ADD uart.conf /etc/supervisor/conf.d
ADD net_monitor.conf /etc/supervisor/conf.d

WORKDIR /app/wifi-connect/scripts
RUN chmod +x raspbian-install.sh
RUN ./raspbian-install.sh

WORKDIR /app
RUN chmod 774 docker-entrypoint.sh
ENTRYPOINT ["bash", "docker-entrypoint.sh"]

When I run raspbian-install.sh in the container, I got the following error.

I have already met with two errors and solved them by installing systemd in the container and deleting all sudo in raspbian-installer.sh file, but I don’t have an idea to solve the above issue.
I’m guessing this is related to the dbus setting on the Raspbian.

I hope you help me about this problem.
Thanks in advance.
Anatoli

Hi there, I think the reason is permissions and not having dbus available. Can you try installing dbus and see if that helps: Here’s a quick SO guide I found: https://unix.stackexchange.com/questions/546726/setup-docker-container-to-communicate-with-host-over-d-bus

Hi @sradevski
Thanks for your reply.
I’ll try this soon.

Hi @sradevski
I still have a few question about the guide you recommend.

  1. Can I use dbus.conf file without any changes? It seems this guide is based on using Ubuntu16.04. But I’m working on Raspberry Pi.

  2. How can I set DBUS_SESSION_ADDRESS variable?

    export DBUS_SESSION_BUS_ADDRESS=tcp:host=${containerIp},port=6667,family=ipv4
    

    Where should I add this command? I just need to run this command inside the docker container? Or should I add this to any file? Should I use the raspberry pi IP as continerIP?

  3. As you can see in my screenshot, I run docker-entrypoint.sh by bash command in the end of my Dockerfile. But I see the user app is run by dbus-run-session command in the guide. Should I also use dbus-run-session command, not bash?

Hi Anatoli,

You can skip the copy and entrypoint steps in the guide. The installation of wifi-connect is failing due to dbus not being installed on the image. Try just adding the RUN apt-get install -y dbus line into your Dockerfile and retrying.

You might run into issues running the container, in which case you might want to make the host dbus socket when issuing the docker run in which case you might have to link the host socket into the docker container by adding --mount type=bind,source=/var/run/dbus/system_bus_socket,target=/host/var/run/dbus/system_bus_socket -e DBUS_SYSTEM_BUS_ADDRESS="unix:path=/host/run/dbus/system_bus_socket" to the docker run options.

Let us know how it goes

Hi @pipex

Thanks for your help.
After installing dbus package in the web container, I retried to install wifi-connect on it. But I still have the same error.
So I’m trying to link the host dbus socket into the web docker container. But I don’t use docker run command to build the docker image and run the containers. I’m running all the docker containers using docker-compose.yml.
Here is my docker-compose.yml.

Here are my questions.

  1. The dockerfile version I use is 3.0. Does that affect installing wifi-connect into the container?
  2. As you can see, I added a volume to link the host socket into the docker container. I just removed /host in the target. Is it a mistake?
  3. I also added an environment for DBUS_SYSTEM_BUS_ADDRESS. Could you please check if it’s set correctly?
  4. I see type=bind field in docker run options you attached. But I’m not sure how to setup this on my docker-compose.yml. Could you please let me know it?

Thanks in advance.
Anatoli

Hi

I tried docker run command as you mentioned, but I got the following error.


How can I solve this?

Hi

  • Is there something specific that you are looking for with version 3? I was taking a look at the docker docs here and there are some new commands there. Is there something in that you are looking at? I know for a fact that some of our projects that use wifi-connect have 2.1 and they work fine.
  • in the environment you are setting /host/run/dbus whereas in the volumes you have made that var/run/ and removed the host part. I think those two things won’t go well with each other.

Hi @anujdeshpande
Thanks for your help, but I want to install and run wifi-connect inside the web container already running on my pi4. I don’t want the Wi-Fi connection to run as one independent container.
I need the solution to install and run it in the web container.

Hi Felipe,

I’m still waiting for your help.
As you recommended, I first built a web docker image called test:1.0 with the following command.

docker build -t test:1.0 .

After that, I run the container using docker run command with the options you mentioned.
And then I run raspbian-installer.sh file in the container, but I still get the same error.

From https://github.com/balena-io/wifi-connect :

WiFi Connect is designed to work on systems like Raspbian or Debian, or run in a docker container on top of balenaOS.

This raspbian-installer.sh install script is meant to be run on debian or raspbian, not in a container on rasbian.

Wifi-connect relies on NetworkManager running on the host:

WiFi Connect interacts with NetworkManager, which should be the active network manager on the device’s host OS.

The DBUS_SYSTEM_BUS_ADDRESS you set in the container needs to exist in the container, which is not the case in your screenshot above.

Hi Alexis,

So do you mean that it’s impossible to install and use wifi-connect in the web docker container?
And I don’t understand the final sentence.

 DBUS_SYSTEM_BUS_ADDRESS="unix:path=/host/run/dbus/system_bus_socket"

Should I remove /host in the above setting? Can it make wifi-connect work inside the web container?

  • It should work in your “web” container;
  • Don’t remove /host;
  • Bind mount /run/dbus from the host to /host/run/dbus in the container to avoid any confusion;

Please also check my answer in your other thread: WiFi-connect installation in Raspberry Pi Docker container