DEV Community

Fernando Tricas García
Fernando Tricas García

Posted on • Edited on

So, you want to write your first container?

Alt Text

I've tried several times to run my own dockers. Maybe lack of time, or lack of motivation... I did understand (more or less) the concepts but I was unsuccessful.

This time I wanted to test my pet project (I've been working in providing a self-contained version of some scripts I'm using to publish in social networks, using their APIs and some modules developed in Python for them; it is mainly a facade and some program to manage scheduling and so on. Available at socialModules).

So when I saw this post (in Spanish) Filtrando y respondiendo tweets "sin manos" (yes, me too. I have a bot to interact with Twitter, I wanted to see if there were some new ideas. My first tests with Twitter API: Publishing in Twitter when posting here) and given the fact that Jorge devotes some space to containers in the post, I decided to give them a try (again).

So I did a quick search and found Docker for beginners
and followed the instructions.
A failure. Again. Maybe because I'm on fedora 33 and things are not very well integrated, or who knows, the example was not working. I decided to switch to my new Raspberry with the help of How To Install Docker On Raspberry Pi
and some advances happened.

Nevertheless, the examples were not really interesting for me (too much web and JavaScript on their minds), since I wanted to work with my own code: I copied the Dockerfile, adapted it (some work was needed to find the adequate base image), copied the project code (a docker as the complete compartimentalization, to check my project, remember?) and it started to work.
Here you have it:

# our base image
FROM arm32v7/python

# Download latest listing of available packages:
RUN apt -y update
# Install a new package:
RUN apt -y install libxml2 libxslt1.1
# These are needed for some requirements for my python modules.

# upgrade pip
RUN pip install --upgrade pip

# copy files required for the app to run
COPY socialModules /usr/src/app/socialModules
RUN pip install --no-cache-dir -r /usr/src/app/socialModules/requirements.txt
# This is our own code.

# tell the port number the container should expose
EXPOSE 5000
# I think I do not need this.

# run the application
CMD ["python", "/usr/src/app/socialModules/moduleRss.py"]
# First try, a module that can work without configuration
Enter fullscreen mode Exit fullscreen mode

Since this post is becoming quite long, maybe I'll write another one to explain the following steps (with configuration files and podman) but it seems to be working correctly. And, yes, my code should run in any machine with the requirements.txt included and some configuration (documentation: work to be done).

Side note: building with docker reminds me to the compilation process:

sudo docker build . -t ftricas/social
Sending build context to Docker daemon  729.1kB
Step 1/8 : FROM arm32v7/python
 ---> 1e73204649e2
Step 2/8 : RUN apt -y update
 ---> Using cache
 ---> ebc067990e18
Step 3/8 : RUN apt -y install libxml2 libxslt1.1
 ---> Using cache
 ---> 121f5da59404
Step 4/8 : RUN pip install --upgrade pip
 ---> Using cache
 ---> 711373aa4518
Step 5/8 : COPY socialModules /usr/src/app/socialModules
 ---> Using cache
 ---> 9e45c303d29f
Step 6/8 : RUN pip install --no-cache-dir -r /usr/src/app/socialModules/requirements.txt
 ---> Running in 53129fbf152f
Collecting colorama
  Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting twitter
  Downloading twitter-1.18.0-py2.py3-none-any.whl (54 kB)
Collecting facebook-sdk
  Downloading facebook_sdk-3.1.0-py2.py3-none-any.whl (7.5 kB)
Collecting requests
  Downloading requests-2.25.0-py2.py3-none-any.whl (61 kB)
Collecting bs4
  Downloading bs4-0.0.1.tar.gz (1.1 kB)

...
Enter fullscreen mode Exit fullscreen mode

Running the docker once:

pi@ra-amon:~ $ sudo docker run ftricas/social
no
Configured blogs:
Account: Blog1
15
{'id': 'https://mobile.slashdot.org/story/20/11/20/2231238/t-mobile-becomes-first-carrier-to-enable-988-number-for-mental-health-services?utm_source=rss1.0mainlinkanon&utm_medium=feed', 'title': 'T-Mobile Becomes First Carrier To Enable 988 Number For Mental Health Services', 'title_detail': {'type': 'text/plain', 'language': None, 'base': 'http://rss.slashdot.org/Slashdot/slashdotMain', 'value': 'T-Mobile Becomes First Carrier To Enable 988 Number For Mental Health Services'}, 'links': [{'rel': 'alternate', 'type': 'text/html', 'href': 'https://mobile.slashdot.org/story/20/11/20/2231238/t-mobile-becomes-first-carrier-to-enable-988-number-for-mental-health-services?utm_source=rss1.0mainlinkanon&utm_medium=feed'}], 'link': 'https://mobile.slashdot.org/story/20/11/20/2231238/t-mobile-becomes-first-carrier-to-enable-988-number-for-mental-health-services?utm_source=rss1.0mainlinkanon&utm_medium=feed', 'summary': 'T-Mobile has added support for the 988 emergency mental health services number more than a year and a half ahead of the Federal Communications Commission\'s deadline, the company announced on Friday. The Verge reports: T-Mobile customers who dial 988 will be connected to the National Suicide Prevention Lifeline (NSPL) and its network of crisis centers across the US. T-Mobile says it is the first carrier in the US to make 988 available to its customers. T-Mobile chief technology officer Abdul Saad said in a statement that making the shorter emergency number available to customers was "a matter of urgency for us, particularly as the COVID-19 pandemic continues and the holiday season approaches." People in need of mental health support can still contact the NSPL by calling 1-800-273-8255 (1-800-273-TALK) or by using online chats.<p><div class="share_submission">\n<a class="slashpop" href="http://twitter.com/home?status=T-Mobile+Becomes+First+Carrier+To+Enable+988+Number+For+Mental+Health+Services%3A+https%3A%2F%2Fbit.ly%2F3pNJPqy"><img src="https://a.fsdn.com/sd/twitter_icon_large.png" /></a>\n<a class="slashpop" href="http://www.facebook.com/sharer.php?u=https%3A%2F%2Fmobile.slashdot.org%2Fstory%2F20%2F11%2F20%2F2231238%2Ft-mobile-becomes-first-carrier-to-enable-988-number-for-mental-health-services%3Futm_source%3Dslashdot%26utm_medium%3Dfacebook"><img src="https://a.fsdn.com/sd/facebook_icon_large.png" /></a>\n\n\n\n</div></p><p><a href="https://mobile.slashdot.org/story/20/11/20/2231238/t-mobile-becomes-first-carrier-to-enable-988-number-for-mental-health-services?utm_source=rss1.0moreanon&amp;utm_medium=feed">Read more of this story</a> at Slashdot.</p>', 'summary_detail': {'type': 'text/html', 'language': None, 'base': 'http://rss.slashdot.org/Slashdot/slashdotMain', 'value': 'T-Mobile has added support for the 988 emergency mental health services number more than a year and a half ahead of the Federal Communications Commission\'s deadline, the company announced on Friday. The Verge reports: T-Mobile customers who dial 988 will be connected to the National Suicide Prevention Lifeline (NSPL) and its network of crisis centers across the US. T-Mobile says it is the first carrier in the US to make 988 available to its customers. T-Mobile chief technology officer Abdul Saad said in a statement that making the shorter emergency number available to customers was "a matter of urgency for us, particularly as the COVID-19 pandemic continues and the holiday season approaches." People in need of mental health support can still contact the NSPL by calling 1-800-273-8255 (1-800-273-TALK) or by using online chats.<p><div class="share_submission">\n<a class="slashpop" href="http://twitter.com/home?status=T-Mobile+Becomes+First+Carrier+To+Enable+988+Number+For+Mental+Health+Services%3A+https%3A%2F%2Fbit.ly%2F3pNJPqy"><img src="https://a.fsdn.com/sd/twitter_icon_large.png" /></a>\n<a class="slashpop" href="http://www.facebook.com/sharer.php?u=https%3A%2F%2Fmobile.slashdot.org%2Fstory%2F20%2F11%2F20%2F2231238%2Ft-mobile-becomes-first-carrier-to-enable-988-number-for-mental-health-services%3Futm_source%3Dslashdot%26utm_medium%3Dfacebook"><img src="https://a.fsdn.com/sd/facebook_icon_large.png" /></a>\n\n\n\n</div></p><p><a href="https://mobile.slashdot.org/story/20/11/20/2231238/t-mobile-becomes-first-carrier-to-enable-988-number-for-mental-health-services?utm_source=rss1.0moreanon&amp;utm_medium=feed">Read more of this story</a> at Slashdot.</p>'}, 'authors': [{'name': 'BeauHD'}], 'author': 'BeauHD', 'author_detail': {'name': 'BeauHD'}, 'updated': '2020-11-21T10:00:00+00:00', 'updated_parsed': time.struct_time(tm_year=2020, tm_mon=11, tm_mday=21, tm_hour=10, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=326, tm_isdst=0), 'tags': [{'term': 'cellphones', 'scheme': None, 'label': None}], 'slash_department': 'mental-health', 'slash_section': 'mobile', 'slash_comments': '7', 'slash_hit_parade': '7,7,5,4,0,0,0'}
T-Mobile Becomes First Carrier To Enable 988 Number For Mental Health Services https://mobile.slashdot.org/story/20/11/20/2231238/t-mobile-becomes-first-carrier-to-enable-988-number-for-mental-health-services?utm_source=rss1.0mainlinkanon&utm_medium=feed 
Astronomers Discover New 'Fossil Galaxy' Buried Deep Within the Milky Way https://science.slashdot.org/story/20/11/20/2214203/astronomers-discover-new-fossil-galaxy-buried-deep-within-the-milky-way?utm_source=rss1.0mainlinkanon&utm_medium=feed 
Rocket Lab Becomes Second Company After SpaceX To Launch and Land Orbital Rocket https://science.slashdot.org/story/20/11/20/228250/rocket-lab-becomes-second-company-after-spacex-to-launch-and-land-orbital-rocket?utm_source=rss1.0mainlinkanon&utm_medium=feed
Enter fullscreen mode Exit fullscreen mode

The end, as an image:

Alt Text

Top comments (0)