How to find error output from failed CMD["python3", "main.py"] container start


#1

Hi, my dockerfile ends by running a python3 script. However, it seems to be failing silently when the container starts.

If I go into a terminal and run the same script, it works without issue.

There is no output from Python on the dashboard logs at all, though - my understanding is that if the script that the CMD function is supposed to run fails, I should see an error message in the dashboard.

I’m sorry if this is covered somewhere else, but I’ve searched the documentation and can’t find other examples of where to go to look for Python error output if it for some reason does not appear in the dashboard logs.

My project is based off of the debian base image for beaglebone black, riffing off of the simple-server-python example (which works fine!)

Any hints or help would be much appreciated!

AKA


#4

Hey @aka could you share your project? This isn’t something that I have seen before. If the CMD step fails, there should be an error stating this.


#5

Thanks for the reply! I granted a day of support access (https://dashboard.resin.io/apps/951403 ), happy to extend it if need be.

I can ssh into the container after it boots, though, and run my script manually - so maybe I’m wrong, and CMD isn’t “failing,” it’s finishing and I’m just expecting the wrong output?

Thanks for any help you can provide, and my pre-emptive apologies if this is something n00b-related…

AKA


#6

I tried to implement this same project on a Raspi Zero, and am encountering similar difficulties getting the container started.

In the case of the Raspi Zero, I’m not even seeing a main container from the Dashboard view on resin.io - I only see the Host OS machine.

…since the two issues seem to be related (in both cases, the output of CMD isn’t visible in the logs, and I need help understanding what’s going wrong), I’ve granted support access to both projects for a week. (the projects are “orangeCase” on BBB and “speedtestZero” on RasPiZero)

Any observations or diagnoses you can think of, or stuff for me to try, would be much appreciated!

Thanks,

AKA


#7

Hi, looking at your application, can it be that you are running the CMD incorrectly? Would help to see your Dockerfile, but my guess is that you’ll need

CMD ["python3", "src/main.py"]

instead of

CMD ["python3", "main.py"]

as you say in the topic title?

Ad for not seeing the main container, are you deploying the exact same project, or are there any code differences?


#8

Thanks for the reply!

The topic title is wrong, my apologies… my CMD line does in fact point to src/main.py…the Dockerfile for BBB that initiated this topic is available in this thread. The RasPi Zero Dockerfile is here:

# base-image for python on any machine using a template variable,
# see more about dockerfile templates here:http://docs.resin.io/pages/deployment/docker-templates
FROM resin/%%RESIN_MACHINE_NAME%%-debian

# RUN apt-get update && apt-get install -y  && \
#    apt-get clean && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    cron \
    systemd \
    python \
    python-pip \
    pkg-config \
    python-dev \
    python-dbus \
    python-setuptools \
    libusb-1.0.0  \
    libusb-1.0.0-dev  \
    git  \
    cython \
    cython3 \
    g++ \
    cmake \
    git-core  \
    libudev-dev  \
    libusbhid-common  \
    libusb-dev \
    build-essential  \
    python-smbus \
    python3 \
    python3-setuptools \
    python3-dbus \
    python3-pip \
    python3-dev \
    python-smbus \
    python-psutil \
    avahi-daemon \
    avahi-utils \
    libnss-mdns \
    redis-server \
    wireless-tools


# switch on systemd init system in container
ENV INITSYSTEM on

# 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 pip3 install -r /requirements.txt # blink1 library that i like is only for python3!!

# try to install blink1 pip3 library without hitting pypi repo b/c repo is unmaintained
RUN git clone https://github.com/todbot/blink1.git && cd blink1/commandline && make
RUN cd blink1/python/pypi && python3 setup.py install

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

RUN echo "*/1 * * * * cd /usr/src/app/src && python3 spt.py >/proc/1/fd/1" | crontab

# main.py will run when container starts up on the device
CMD ["python3","src/main.py"]

…I found I need to install so many things because I had issues with the default python base image for BBB (more detail on that in the other thread).

I’m not sure how much of the codebase you can see - if there’s something I can do to grant more access/visibility to you, please let me know.

Thanks!

AKA


#9

I see this in the build notes when I git push resin master, does it mean that the container that is running my CMD is being destroyed?

[main]  Step 10/11 : RUN echo "*/1 * * * * cd /usr/src/app/src && python3 spt.py >/proc/1/fd/1" | crontab
[main]   ---> Running in 8607b4878d9c
[main]   ---> 8d78cace5d16
[main]  Removing intermediate container 8607b4878d9c
[main]  Step 11/11 : CMD python3 src/main.py
[main]   ---> Running in 22dc6fecf74c
[main]   ---> 7b32adbd51d4
[main]  Removing intermediate container 22dc6fecf74c
[main]  Successfully built 7b32adbd51d4

…note the last 5 lines, which say my CMD is being run in 22dc6fecf74c, but then also that 22dc6fecf74c is subsequently destroyed…

Sorry if this isn’t germane / helpful…thanks for any suggestions or hints you might have!

AKA


#10

Hey @aka in the build steps docker goes through the Dockerfile and creates the final image. That image will apply the last CMD line that you have defined. In the builds all intermediate containers (that are used just for the build) are destroyed. That CMD also can be anywhere in your Dockerfile, don’t need to be the last one, it will become a metadata in your image. (the distinction between docker images and docker containers is an important one)

And what you point out:

[main]  Step 11/11 : CMD python3 src/main.py
[main]   ---> Running in 22dc6fecf74c
# ^^ this is the container that the builder uses to further build your "image"
[main]   ---> 7b32adbd51d4
# ^^ this is the resulting container after this step, so the new container
[main]  Removing intermediate container 22dc6fecf74c
# ^^ the intermediate one, that the CMD line started with is unnecessary
[main]  Successfully built 7b32adbd51d4
# ^^ since that was the last step, the resulting container will become the final image, that's the same number as above

Hope this helps a bit!