Access service via hotspot

Hello! I have a multi-container setup. One “Create React App” static app in nginx and another container running a python Flask app. I am in dev mode and have a hotspot working great on an RPI 4 and I can access the internet from it when I have ethernet connected also. I do not need internet access though.

I can access the Rpi via ethernet by its hostname and can access my web app and everything can communicate.

I’ve searched through the forums but I’m not sure: how to access the service on the Rpi on port 80 I have exposed when connected to the Rpi as a hotspot?

Hi
Can you share your docker-compose file? Would like to better understand how services are architected.

If I understand correctly, you have a device that acts as a hotspot, but is not passing the 80 port to the right service. Is that right?

I believe your understanding is correct. I’m looking for connecting to the service on port 80 while connected to the device via a hotspot. Maybe I need to connect to the IP of the Pi? Or maybe DHCP needs set up? Maybe there is a hostname I can connect to access my service?

Sure thing:

docker-compose.yml

version: '2'
services:
  web:
    build: ./src/web
    expose:
      - "80"
    network_mode: host
    depends_on:
      - server
  server:
    build: ./src/server
    privileged: true
    network_mode: bridge
    ports:
      - "5000:5000"

web/dockerfile.template
(I know I have some hardcoded URLs :wink: - Also I’m exposing 2 ports, I know that is bad practice but I can remove that once I get the hotspot working )

#https://mherman.org/blog/dockerizing-a-react-app/#docker
# build environment
FROM balenalib/%%BALENA_MACHINE_NAME%%-node as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
#ENV REACT_APP_SERVER_URL /server

COPY package.json ./
COPY yarn.lock ./
RUN yarn install --frozen-lockfile
RUN npm install react-scripts@3.4.1 -g --silent
COPY . ./
ENV REACT_APP_SERVER_URL http://e7a539b.local:5000/
RUN npm run build

# production environment
#FROM nginx:stable-alpine
FROM arm64v8/nginx:1.17.10-alpine
COPY --from=build /app/build /usr/share/nginx/html
#COPY default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

server/dockerfile.template

# base-image for python on any machine using a template variable,
# see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/
FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-stretch-run

# use `install_packages` if you need to install dependencies,
# for instance if you need git, just uncomment the line below.
# TODO: This adds ~120mb, all I saw we needed was gcc
RUN install_packages build-essential

# Set our working directory
WORKDIR /usr/src/app

# Copy requirements.txt first for better cache on later pushes
COPY requirements.txt requirements.txt

# pip install python deps from requirements.txt on the resin.io build server
RUN pip install -r requirements.txt

# This will copy all files in our root to the working  directory in the container
COPY ./ ./

# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1

# main.py will run when container starts up on the device
CMD ["python","-u","main.py"]

And just to be clear here is my barebone requirements and workflow:

This device will be offline most of the time.
Turn on (with no internet access/no ethernet) -> connect to wifi hotspot -> access web app service via ip hostname or whatever is recommended. It can be hardcoded as a bookmark or anything that is easiest.

Interacting with the web app service will of course make server calls to python to interact with GPIO.

I do not need any internet sharing or anything like that.

Maybe bluetooth is more appropriate for my use case? I’ve seen Balena tutorials for web bluetooth. I just thought WiFi may be more “straightforward”.

Hi,

Is the RPi that’s acting as a hot spot handing out its own addresses? And if so, is your Python-app device getting an address on a separate subnet? Presuming that your workstation has access to the hot spot subnet (either through its own wifi or route configuration), that would allow you to reach the RPi and any of its connected devices.

So, if the RPi hot spot has an address of 192.168.1.50 and it’s handing out NATted addresses like 10.10.10.0/24, presumably your Python-app device should get an address like 10.10.10.2 and you should be able to reach the web server at 10.10.10.2:80. If the hot spot is passing through your 192.168.1.0/24 addresses (and handing out a range of those), then your Python-app device would be listening on its own address, like 192.168.1.51:80.

Have I got that right?

John

SOLVED

Correct @jtonello it was handing out its own addresses.
Following your explanation I ran balena device my_device and got the IP addresses:

  • 192.168.0.6 (My ethernet connected home network)
  • 10.42.0.1 (The hotspot network)

When connected to the hotspot I was handed 10.42.0.9.

I was then able to connect to the hotspot and navigate to http://10.42.0.1 (80) and :5000 and both services served up as expected!

I did need to change my environment variable in my dockerfile which seems hardcoded but works for me: ENV REACT_APP_SERVER_URL http://10.42.0.1:5000/

Thanks for the help @anujdeshpande and @jtonello (marked jtonello’s post as the solution)

That’s great to hear Lane and happy we could help!