React Front End with NGINX and an Express Backend. Can't Find Backend Server

So it’s demo day tomorrow and our team hasn’t been able to make a lot of progress on the following issue. Never fails when you have to demo something :slight_smile:

We have a multiple container setup with the following Docker Compose file.

version: "2.0"

services:
  client:
    build: "./client"
    privileged: true
    network_mode: host
    depends_on:
      - server
  server:
    build: "./server" # use this directory as the build context for the service
    privileged: true
    network_mode: host
    restart: "always"
    labels:
      io.balena.features.kernel-modules: "true"
      io.balena.features.firmware: "true"
    environment:
      CAN0_BITRATE: 250000
  stream-server:
    build: "./stream-server" # use this directory as the build context for the service
    privileged: true
    network_mode: host
    restart: "always"
    labels:
      io.balena.features.kernel-modules: "true"
      io.balena.features.firmware: "true"

I have all of the containers in host mode as the server is using socket CAN.

We can build and deploy the containers using local mode (which takes a lot of time) and when they startup the client can’t see the server unless we but in the IP address of the RPi running Balena. This is not ideal as we won’t know the IP of the device when it’s deployed and it may not be connected to a network all the time.

Our Nginx config file is

server {
  listen 80;
  
  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
    try_files $uri $uri/ /index.html =404;
  }
  
  include /etc/nginx/extra-conf.d/*.conf;
}

I believe I am not setting up nginx correctly and I have read the docs but those left me more lost.

Thanks.

@klutchell Maybe you have some thoughts on this?

Hey Darren, if all the containers are in host networking mode as you have above, they should be able to reach each other via 127.0.0.1:port, is that what you’ve been trying?

I’ve never heard of SocketCAN until now so I don’t know what other impacts that may have or what else you’ve tried.

I did find another forum post that may be of help:

@klutchell thanks for the reply. We have been using http://localhost:port to connect but that doesn’t seem to work. Are we experiencing a DNS issue with resolving localhost?

SocketCAN allows you to interact with a CAN device over a network socket.

Thanks,

Hi there, try curl http://localhost:{{port}} from the hostOS to see what the response is (if any). That should give you some hints to go on…