Help creating container.

I apologise for my lack of knowledge, still on a steep learning curve with Balena.

I have an ADSB container which runs well on a Raspberry Pi and am trying to create another container with code from GitHub.

For ease, this is how my following files look…

/adsbcot/Dockerfile.template

FROM balenalib/%%BALENA_ARCH%%-debian:buster AS base
LABEL maintainer=""

# GENERAL
ENV GIT_SOURCE="https://github.com/ampledata/adsbcot.git"
ENV GIT_BRANCH="main"
ENV SRC_PATH="/src/adsbcot"
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2

ENV RECEIVER_HOST dump1090-fa
ENV RECEIVER_PORT 30005

RUN apt-get update && \
    apt-get install -y \
    curl \
    python \
    python3 \
    build-essential \
    python-dev \
    python3-pip \    
    git \
    libatlas-base-dev \
    libpcap-dev && apt-get clean

RUN mkdir /src && mkdir -p /usr/share/adsbcot
RUN git clone -b ${GIT_BRANCH} --depth 1 ${GIT_SOURCE} ${SRC_PATH}

COPY start.sh /

RUN chmod +x /start.sh 

ENTRYPOINT ["/start.sh"]

/adsbcot/start.sh

#!/usr/bin/env bash
set -e

# Check if service has been disabled through the DISABLED_SERVICES environment variable.

if [[ ",$(echo -e "${DISABLED_SERVICES}" | tr -d '[:space:]')," = *",$BALENA_SERVICE_NAME,"* ]]; then
        echo "$BALENA_SERVICE_NAME is manually disabled."
        sleep infinity
fi

# Verify that all the required varibles are set before starting up the application.

echo "Verifying settings..."
echo " "
sleep 2

missing_variables=false
        
echo " "

if [ "$missing_variables" = true ]
then
        echo "Settings missing, aborting..."
        echo " "
        sleep infinity
fi

echo "Settings verified, proceeding with startup."
echo " "

# Start adsbcot and put it in the background.
cd /usr/share/adsbcot
adsbcot -U tcp:x.x.x.x:8087 -D tcp+beast:127.0.0.1:30005 &

# Wait for any services to exit.
wait -n

/docker-compose.yml

version: '2'
volumes:
  settings:
services:
  dump1090-fa:
    build: ./dump1090-fa
    image: dump1090-fa
    restart: always
    environment:
      - LAT=
      - LON=
      - ALT=
    devices:
      - "/dev/bus/usb"
    expose:
      - "30001"
      - "30002"
      - "30003"
      - "30004"
      - "30005"
      - "30102"
      - "30104"
      - "30105"
      - "30106"
      - "8080"
    ports:
      - "30001:30001"
      - "30002:30002"
      - "30003:30003"
      - "30004:30004"
      - "30005:30005"
      - "30102:30102"
      - "30104:30104"
      - "30105:30105"
      - "30106:30106"
      - "8080:8080"
  piaware:
    depends_on:
      - dump1090-fa
    build: ./piaware
    image: piaware
    restart: always
    environment:
      - FLIGHTAWARE_FEEDER_ID=
  adsbcot:
    depends_on:
      - dump1090-fa
    build: ./adsbcot
    image: adsbcot
    restart: always

Essentially, I would like to install / git clone the adsbcot code from Github into a container and then start the code with the command adsbcot -U tcp:x.x.x.x:8087 -D tcp+beast:127.0.0.1:30005 &

Everything seems to build correctly, however the container isn’t running and I get the error…

 adsbcot  Verifying settings...
 adsbcot   
 adsbcot   
 adsbcot  Settings verified, proceeding with startup.
 adsbcot   
 adsbcot  /start.sh: line 68: adsbcot: command not found

Can anyone assist where I may be going wrong please, I am hoping it is a simple solution.

Many thanks.

Hi @tissy, it looks like the service can’t find the binary adsbcot. You should try and list the contents of the /usr/share/adsbocot directory which is where I presume this binary is at to verify it exists. You can add a ls command in the start.sh script:

cd /usr/share/adsbcot
ls -al /usr/share/adsbcot
adsbcot -U tcp:x.x.x.x:8087 -D tcp+beast:127.0.0.1:30005 &

Then examine the logs and see if the binary exists, if it doesn’t it’s possible you are missing some of the steps detailed here: GitHub - ampledata/adsbcot: ADS-B to Cursor on Target (CoT) Gateway for ATAK & WinTAK SA platforms.

If you don’t mind I have a few suggestions to improve your docker-compose file since you mentioned you are new with balena/docker:

  1. While technically you can use build and image to build the image from build and tag it as image, I don’t think it’s your intended use case here and can lead to confusion. I suggest removing the image tag, so you should have:
services:
  dump1090-fa:
    build: ./dump1090-fa
    restart: always
...
  1. Exposing ports via expose is not needed if you are already exposing them via ports. expose will expose ports to other containers inside your device while ports will expose them to both containers inside your device and anything outside it. So you can remove the expose section.

  2. I suggest you look at developing with local mode: Develop locally - Balena Documentation. When you put a device in local mode you can then push releases to it directly from your development computer without going through balena builders (so you don’t need to create a release, then the device downloads it, and runs it). It’s a MUCH faster development experience. You need to set your device to local mode using the dashboard then push code to it using balena push <DEVICE_IP>; the code will be pushed to your device and any changes you make on your dev computer will instantly trigger a re-build on the device and it’ll get updated. This is pretty powerful!

  3. If you are using a balenalib base image (Balena base images - Balena Documentation) you can also use balena-idle special command, it’s basically the same as sleep infinity. For example, you can add balena-idle/ sleep infinity to your /adsbcot/start.sh script just before you make the call to adsbcot -U tcp:x.x.x.x:8087 -D tcp+beast:127.0.0.1:30005 &. Then once the container is “idle” you can SSH into it (balena ssh <DEVICE_IP> <SERVICE_NAME>) and inspect the files in there.

Let me know if this was useful, hope you manage to beat that learning curve!

Thank you so much @tmigone for taking the time to reply. You were most helpful and I think I am making some progress. Thank you also for your suggestions, I will work through them.

I was missing a couple of steps as you suggested, so they have now been rectified.

My Dockerfile.template now looks like this…

FROM balenalib/%%BALENA_ARCH%%-debian:buster AS base
LABEL maintainer=""

# GENERAL
ENV GIT_SOURCE="https://github.com/ampledata/adsbcot.git"
ENV GIT_BRANCH="main"
ENV SRC_PATH="/src/adsbcot"
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2

ENV RECEIVER_HOST dump1090-fa
ENV RECEIVER_PORT 30005

RUN apt-get update && \
    apt-get install -y \
    curl \
    python \
    python3 \
    build-essential \
    python-dev \
    python3-pip \    
    git \
    libatlas-base-dev \
    libpcap-dev && apt-get clean

RUN mkdir /src && mkdir -p /usr/share/adsbcot

RUN git clone -b ${GIT_BRANCH} --depth 1 ${GIT_SOURCE} ${SRC_PATH} && \
    cd src/adsbcot && \
    sudo python setup.py install

COPY start.sh /

RUN chmod +x /start.sh 

ENTRYPOINT ["/start.sh"]

It now seems to be having issues clone the Git correctly. I am getting the following error on build which when I have completed this on a non-balena instance, cloning and installation works fine.

Any further suggestions would be greatly appreciated as it may be something simple I am doing wrong.

Can anyone offer advice on the above please? :slight_smile:

Many thanks for your help.

That error indicates the issue is actually within the setup.py file, which you are grabbing from an external GitHub repo, so you might need to check with the owner/maintainer of that repo. It might be that the package is not meant to be installed in a container, or could be a simple versioning issue or missing variable declaration. On the other hand, just glancing at the naming, if you attempting to deploy a Flight Tracker, you might give this project a try: GitHub - ketilmo/balena-ads-b: ADS-B Flight Tracker running on balena with support for FlightAware, Flightradar24, PlaneFinder, OpenSky Network, RadarBox and ADSB Exchange.

I think I am getting somewhere and have the Git repository now cloned and the build runs without obvious errors.

However, when the container is running, it is throwing a load of errors. I’m guessing I am still missing a dependency or two? How would I go about finding what is missing please?

Hi there,

The error in your screenshot doesn’t suggest it’s a dependency issue, but a bug in the librtlsdr.py code. This won’t be something that we can help you with on this forum as it’s an issue with the project itself. The best thing to do is to add an issue on the balena-ads-b repository: GitHub - ketilmo/balena-ads-b: ADS-B Flight Tracker running on balena with support for FlightAware, Flightradar24, PlaneFinder, OpenSky Network, RadarBox and ADSB Exchange.
Ketil is a great member of the balena community, and will help here. :slight_smile:

Phil