We have our base container with Python3, PyQt5, CharLCD and iot_message: bkosciow/rpi-qtpython.
Today we will learn how to get files from GitHub and put them into image.
Quick look at documentation says that ADD directive may do what we want. Copy archive and unpack it.
I got url to zip archive from GitHub and added entry to Dockerfile:
ADD https://github.com/bkosciow/proxy_lcd/archive/master.zip /app
rebuild container and… fail.
File was only downloaded but not extracted, google to the rescue and.. it is not possible with zip files… there was an issue back in 2015 but still no go:(. But we can get tar.gz from GitHub.. maybe it will solve this:
ADD https://github.com/bkosciow/proxy_lcd/archive/master.tar.gz /app
and another fail! Why?
But when I downloaded packed file and used ADD file /app then it worked.
So it seems that unpacking url is not working. Great Another little detail that makes me angry at docker.
What now? We have to do this manually. First install unzip and wget into container and then get file and unzip:
RUN apt-get -y install unzip wget RUN wget https://github.com/bkosciow/proxy_lcd/archive/master.zip && unzip master.zip
And it is almost good! It extract files to subfolder so we only need to change WORKINGDIR.
Finally, after some troubles Dockerfile looks like this:
FROM bkosciow/rpi-qtpython RUN apt-get -y install unzip wget RUN wget https://github.com/bkosciow/proxy_lcd/archive/master.zip && unzip master.zip WORKDIR /app/proxy_lcd-master EXPOSE 5054 CMD python3.4 -u ./main.py --cli
Last line starts a script in cli mode. Why -u ? Because without it output was buffered and wasn’t displayed (we have small amount of text:P)
It should be easy 🙂 Mapping two ports and done! But why I have this strange feeling that UDP broadcast would be problematic…
We will see, lets begin with base docker-compose.yml file:
version: "2.1" services: proxylcd: build: . ports: - "5054:5054" - "5053:5053/udp"
next run it via
And it started !
Seems good. Telnet to it from Raspberry:
telnet 127.0.0.1 5054
and.. connected. Looking good. Now type some text and… nothing.. remote lcds do not receive anything.. woops.
After another portion of googling I know that there are some problems with UDP and broadcast. But I found solution, add network_mode in docker-compose. While it is not perfect, it works.
version: "2.1" services: proxylcd: build: . ports: - "5054:5054" - "5053:5053/udp" network_mode: "host"
Real live usage
There is no need to build image at your own. If you want to use it just create a new docker-compose.yml with:
version: "2.1" services: proxylcd: image: bkosciow/arm-proxylcd ports: - "5054:5054" - "5053:5053/udp" network_mode: "host"
And start it via:
docker-compose up -d
I totally forgot about access to settings.ini! As is now we cannot change settings easily – this is bad 🙂 We need to fix this, quickly.
I think best way is to put settings.ini into its own directory and map it via docker volumes. But we have another problem, when we map directory to host we cannot see existing file, we have an empty dir. To do something with it lets change code so if settings is not found app will create default one.
Little tweaks and it is ready and works 🙂
We learned how to get files into Docker container and run a Python script.
Image for ProxyLCD for Raspberry Pi is here: https://hub.docker.com/r/bkosciow/arm-proxylcd/
What about other platforms? Hmm we will see…