Really new to belena and trying to get my head around containers. I have a fairly simple python file which I have copied from the GitHub source. Does this Dockerfile.template look right please as although it compiles fine, when I try to access the docker in Balena.io, it cannot spawn the shell.
#FROM balenalib/%%BALENA_ARCH%%-debian:buster AS base
FROM balenalib/%%BALENA_MACHINE_NAME%%-python:3-stretch-run
ARG PERM_INSTALL="python python3 python-dev python3-pip"
RUN apt update && \
apt install -y $PERM_INSTALL && \
apt clean && apt autoclean && apt autoremove && \
rm -rf /var/lib/apt/lists/*
#FROM base AS buildstep
RUN apt update && \
apt install -y $TEMP_INSTALL
WORKDIR /usr/src/app
COPY adsb2cot.py adsb2cot.py
CMD ["python", "adsb2cot.py"]
Regarding your Dockerfile.
Installing python (through PERM_INSTALL) in your Dockerfile when you’re already running a python base image shouldn’t be necessary. This is however harmless.
I don’t see any definition for TEMP_INSTALL, so I would expect this step to fail.
Regarding connection to your container.
What is the script you are trying to run?
If it’s something short-lived like "print a line and then exit ", then your container will exit before you have the chance to connect to it.
Supervisor will see your container has exited and restart it.
You might want to try running something with an infinite loop in it to make sure your container remains available for connections.
Hello,
What you are running into is nothing specific to balenaOS, it is in fact standard docker behaviour.
Basically, any docker ‘container’ exists only as long as process it is spawned around exists. In your case, adsb2cot.py must be a very short lived process, which causes the container to be short lived as well, which is why you can’t ssh into the container.
As an experiment, you could try adding (something like) time.sleep() in the code which will give you some time to ssh into the container. In real life, processes (and therefore containers) are not that short lived. They wait [forever] on events from hardware or network or other processes.