Pushing Docker Image

docker
#1

Hi everyone,
I have a IOT2000 (x86 based) device running with Balena OS. I have a balenalib/iot2000-ubuntu image on local PC. I have downloaded some dependencies and compiled some code on it which runs correctly.
I saved this container as a new image. I also have it available on my docker hub account.

I want to push this container on the device running Balena OS now and see if it works there. I have read, this is a wrong way of generating Docker Images, but I need to quickly try if my code can run on the hardware.

What should be the steps to achieve this? I believe it has something to do with https://www.balena.io/docs/reference/base-images/custom-docker-base-images/ but I am not sure what are the exact steps once that is done.

Also, once this is achieved will my compiled code and libraries be available to use directly on my device container? A little bit confused here. I want to avoid all the building and compiling of the code on the device.

Update: I made a dockerfile in a folder as following:
FROM repository name

CMD [“bash”]

I went to this folder and did a sudo balena push

Would this be a correct way to do it?

Thanks for your help

0 Likes

#4

Hey @controlsgeek, It seems like you have figured it out, but basically there 2 ways to do it. you can either do it from a single container using Dockerile like this:

FROM shaunmulligan/myPrivateImage

CMD ["bash", "run-something.sh"]

or from a docker-compose.yml in multicontainer like so:

version: '2'
services:
  frontend:
    image: shaunmulligan/myPrivateImage
0 Likes

#5

Thanks @shaunmulligan. I was attempting to do that, but I kept getting the following error:

[Could not communicate with local mode device]. I am able to ping the device at that IP and also ssh into it.

I have the device in my Balena dashboard, and switched to ‘local mode’.
Does the Resin OS 2.12.7+rev2 dev not support local mode yet ?

What would be an alternative method to push this image?

Thanks

0 Likes

#6

Ah @controlsgeek unfortunately its probably due to your device OS version not meeting the minimum OS requirements for balena push <IP>, take a look here https://www.balena.io/docs/learn/develop/local-mode/#local-mode-requirements .

What device type are you working on?

0 Likes

#7

I am using the Siemens IOT2000 board.
Do I have to push it through git if the local mode doesn’t work?

0 Likes

#8

Yes, pushing through git should do the job.

0 Likes

#9

Thanks @samothx. I will try this soon and will update the thread if I was successful in creating a container on IOT2000.

0 Likes

#10

@shaunmulligan @samothx
I was able to download my container through git to IOT2000. But the container kept starting, exiting and restarting.

Running the container as “docker run imagename” works correctly on my PC and does not exit.

The original image I used was “balenalib/iot2000-ubuntu”.
I ssh’ed into this image on my PC, and compiled some libraries and committed this image as a new image.
I built a dockerfile which then used this image in “FROM” and runs a script present inside the image. This dockerfile was used to build the image through balena and upload on IOT2000.

Is there anything wrong with this process that is should not work? When on PC running uname inside the container I get x86_84 for machine, processor and hardware platform. Whereas uname inside balena OS on IOT 2000, I get i586 for machine and processor, and i386 for hardware platform.

Should the balenalib/iot2000-ubuntu image work correctly on IOT2000 without any issue?

Thanks for all your help.

0 Likes

#11

Hi @controlsgeek,

you are trying to create a i386 image on a arm64 / x86_64 platform, so what you are attempting is basically to create an image for a different platform on your pc.
You could use something like the linux file command inside the container to check what platform your binaries are compiled for, example:

file /bin/cp
/bin/cp: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=9720743c3b9fbf61b6f38b7568c10a6dbed05a61, stripped

Can you also share the Dockerfile you use to create that image ?

Regards
Thomas

0 Likes

#12

@samothx

The dockerfile which I had used was:

FROM controlsgeek/iot2000_pyfmi
WORKDIR "/home/JModelica/bin"
ENTRYPOINT "./test.sh"
CMD ["tail", "-f", "/dev/null"]

where controlsgeek/iot2000_pyfmi was the image generated by ssh’ing into “balenalib/iot2000-ubuntu”, installing everything and then “docker commit” it as “controlsgeek/iot2000_pyfmi”

I thought since I am deriving my image from i386 ubuntu container, it shouldn’t matter.

I just made a new Dockerfile which does all the installation:

FROM balenalib/iot2000-ubuntu:xenial

RUN apt-get update 
RUN apt-get install -y --no-install-recommends \
	less \
	kmod \
	nano \
	net-tools \
	ifupdown \
	iputils-ping \
	i2c-tools \
	usbutils \
	g++ \
	subversion \
	gfortran \
	ipython \
	cmake \
	swig \
	ant \
	openjdk-8-jdk \
	python-dev \
	python-numpy \
	python-scipy \
	python-matplotlib \
	cython \
	python-lxml \
	python-nose \
	python-jpype \
	zlib1g-dev \
	libboost-dev \
	&& rm -rf /var/lib/apt/lists/*

COPY JModelica.org /home/JModelica.org

RUN apt-get update && apt-get install make

WORKDIR /home/JModelica.org
RUN rm -rf build
RUN mkdir build
WORKDIR /home/JModelica.org/build
RUN ../configure --prefix=/home/JModelica --disable-openmp
RUN make install 

COPY test.fmu /home/JModelica/bin
COPY testfmu.py /home/JModelica/bin
COPY test.sh /home/JModelica/bin

WORKDIR "/home/JModelica/bin"
ENTRYPOINT "./test.sh"
CMD ["tail", "-f", "/dev/null"]

Do you think this will work correctly when I do a “git push balena master” ?

0 Likes

#13

Hi @controlsgeek,

I think that your new docker file should work fine.

Did you had the occasion to push it? Did it work?

0 Likes

#14

Hi @spanceac
I tried to push it, but I having an error during build (make error), which I did not encounter on my local PC. I am trying to find the issue. Any hints?

0 Likes

#15

Hi @controlsgeek,

You could paste the errors here and maybe we will have some ideas

0 Likes

#16

This is the build error from Balena server. But it works perfectly on my PC. So I was not sure if it was some mistake with the settings.

[main]      ---> c7d947e1b6c3
[main]     Removing intermediate container 0b4a54b224f6
[main]     Step 11/17 : RUN make install
[main]      ---> Running in 4b697d71c0a5
[main]     Making install in ThirdParty/winpthreads
[main]     make[1]: Entering directory '/home/JModelica.org/build/ThirdParty/winpthreads'
[main]     mkdir -p ../../winpthreads_build && \
[main]     cd ../../winpthreads_build
[main]     cp -r /home/JModelica.org/build/../ThirdParty/winpthreads/winpthreads/* /home/JModelica.org/build/ThirdParty/winpthreads/../../winpthreads_build/
[main]     case x86_64-unknown-linux-gnu in \
[main]     *-cygwin*|*-mingw*) \
[main]     cd ../../winpthreads_build && ./configure && make CFLAGS=-m32 LDFLAGS=-m32 RCFLAGS='-F pe-i386'  DESTDIR= && make CFLAGS=-m32 LDFLAGS=-m32 RCFLAGS='-F pe-i386'  DESTDIR= ;; \
[main]     esac
[main]     make[2]: Entering directory '/home/JModelica.org/build/ThirdParty/winpthreads'
[main]     make[2]: Nothing to be done for 'install-exec-am'.
[main]     make[2]: Nothing to be done for 'install-data-am'.
[main]     make[2]: Leaving directory '/home/JModelica.org/build/ThirdParty/winpthreads'
[main]     make[1]: Leaving directory '/home/JModelica.org/build/ThirdParty/winpthreads'
[main]     Making install in ThirdParty/SuperLU
[main]     make[1]: Entering directory '/home/JModelica.org/build/ThirdParty/SuperLU'
[main]     mkdir -p ../../superlu_build && \
[main]     cd ../../superlu_build
[main]     cp -r /home/JModelica.org/build/../ThirdParty/SuperLU/superlu_mt_3.1/* /home/JModelica.org/build/ThirdParty/SuperLU/../../superlu_build/
[main]     case x86_64-unknown-linux-gnu in \
[main]     *-cygwin*|*-mingw*) \
[main]     cd ../../superlu_build && make blaslib EXTRA_CFLAGS=-m32  DESTDIR= && make superlulib EXTRA_CFLAGS=-m32  DESTDIR= ;; \
[main]     *-apple*) \
[main]     cd ../../superlu_build && make blaslib  DESTDIR= && make superlulib  DESTDIR= ;; \
[main]     *) \
[main]     cd ../../superlu_build && make blaslib  DESTDIR= && make superlulib  DESTDIR= ;; \
[main]     esac
[main]     make[2]: Entering directory '/home/JModelica.org/build/superlu_build'
[main]     ( cd CBLAS; make )
[main]     make[3]: Entering directory '/home/JModelica.org/build/superlu_build/CBLAS'
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c isamax.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c sasum.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c saxpy.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c scopy.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c sdot.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c snrm2.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c srot.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c sscal.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c sgemv.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c ssymv.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c strsv.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c sger.c
[main]     gcc -D__OPENMP -g -O3 -fPIC  -DAdd_ -I../SRC -c ssyr2.c
[main]     ar cr ../lib/libblas_OPENMP.a isamax.o sasum.o saxpy.o scopy.o sdot.o snrm2.o srot.o sscal.o  \
[main]     	sgemv.o ssymv.o strsv.o sger.o ssyr2.o
[main]     ar: ../lib/libblas_OPENMP.a: No such file or directory
[main]     make[3]: *** [single] Error 1
[main]     
[main]     Makefile:67: recipe for target 'single' failed
[main]     make[3]: Leaving directory '/home/JModelica.org/build/superlu_build/CBLAS'
[main]     Makefile:30: recipe for target 'blaslib' failed
[main]     make[2]: Leaving directory '/home/JModelica.org/build/superlu_build'
[main]     make[2]: *** [blaslib] Error 2
[main]     
[main]     make[1]: *** [all-local] Error 2
[main]     
[main]     Makefile:421: recipe for target 'all-local' failed
[main]     make[1]: Leaving directory '/home/JModelica.org/build/ThirdParty/SuperLU'
[main]     Makefile:434: recipe for target 'install-recursive' failed
[main]     make: *** [install-recursive] Error 1
[main]     
[main]     Removing intermediate container 4b697d71c0a5
[Info]     Uploading images
[main]     The command '/bin/sh -c make install' returned a non-zero code: 2
[Success]  Successfully uploaded images
[Error]    Some services failed to build:
[Error]      Service: main
[Error]        Error: The command '/bin/sh -c make install' returned a non-zero code: 2
[Error]    Not deploying release.
0 Likes

#17

Hi @spanceac

I changed the docker file to use a pre compiled python package for testing,

FROM balenalib/iot2000-ubuntu:xenial

RUN apt-get update 
RUN apt-get install -y --no-install-recommends \
	less \
	kmod \
	nano \
	net-tools \
	ifupdown \
	iputils-ping \
	i2c-tools \
	usbutils \
	python-dev \
	python-numpy \
	python-scipy \
	&& rm -rf /var/lib/apt/lists/*

RUN apt-get update 

WORKDIR /home

RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
RUN python get-pip.py
RUN python -m pip install https://github.com/CATIA-Systems/FMPy/archive/develop.zip

COPY test1.sh /home/test.sh
COPY testfmu.py /home/testfmu.py

ENTRYPOINT "./test.sh"
CMD ["tail", "-f", "/dev/null"]

It did a successful “git push balena master” and the service was updated on the device but I still have the same issue.

This is what I see in logs. This keeps happening:

12.04.19 15:05:43 (-0400) Service exited 'main sha256:76ac62b87c297909b542c4f3e81727a49caa6a32a36ac693d9fcb7a8b733104b'
12.04.19 15:06:19 (-0400) Restarting service 'main sha256:76ac62b87c297909b542c4f3e81727a49caa6a32a36ac693d9fcb7a8b733104b'
12.04.19 15:06:23 (-0400) Service exited 'main sha256:76ac62b87c297909b542c4f3e81727a49caa6a32a36ac693d9fcb7a8b733104b'
12.04.19 15:07:23 (-0400) Restarting service 'main sha256:76ac62b87c297909b542c4f3e81727a49caa6a32a36ac693d9fcb7a8b733104b'
12.04.19 15:07:27 (-0400) Service exited 'main sha256:76ac62b87c297909b542c4f3e81727a49caa6a32a36ac693d9fcb7a8b733104b'

Update: 1
I ssh’ed into the device host and tried to see what is happening. I got ‘exit 132’. What must be going wrong here?

root@localhost:~# balena ps -a
CONTAINER ID        IMAGE                                        COMMAND                   CREATED              STATUS                            PORTS               NAMES
62501c997d07        76ac62b87c29                                 "/bin/sh -c \"./tes..."   About a minute ago   Exited (132) About a minute ago                       sleepy_lamport
018f742402d4        resin/i386-nlp-supervisor:v7.4.3_logstream   "./entry.sh"              About an hour ago    Up About an hour (healthy)                            resin_supervisor

Update 2
I pulled the “balenalib/iot2000-ubuntu:xenial” image in device and tried to run it in container. It exited with the same exit code. Shown below. I guess the image is somehow not compatible with the hardware. Any suggestions?

root@localhost:~# balena images
REPOSITORY                                                       TAG                 IMAGE ID            CREATED             SIZE
registry2.balena-cloud.com/v2/1d87e268c00d6aa99b4a63f4e9d20d97   <none>              76ac62b87c29        3 hours ago         424MB
balenalib/iot2000-ubuntu                                         xenial              ee0363828a88        3 days ago          190MB
resin/i386-nlp-supervisor                                        v7.4.3_logstream    7e9f8dda1a9e        8 months ago        58.4MB
root@localhost:~# balena run --name ubuntu -it ee0363828a88 bash
root@localhost:~# balena ps -a
CONTAINER ID        IMAGE                                        COMMAND                  CREATED             STATUS                       PORTS               NAMES
e8525c36b324        ee0363828a88                                 "/usr/bin/entry.sh..."   15 seconds ago      Exited (132) 6 seconds ago                       ubuntu
018f742402d4        resin/i386-nlp-supervisor:v7.4.3_logstream   "./entry.sh"             2 hours ago         Up 2 hours (healthy)                             resin_supervisor

If I switch on the Debug flag, it prints

DEBU[0011] [hijack] End of stdout  

and logs is empty.

Thanks

0 Likes

#18

@controlsgeek, it sounds like the ubuntu base images are missing the adaptions that are needed to run on the i386-nlp CPU, I remember when we first supported this CPU it had a number of issues that had to be hacked around due to the CPU instruction Errata. @nghiant2710 do you know of any reason why the balenalib/iot2000-ubuntu:xenial base images errors out with exti 132 ?

0 Likes