<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thesi</title>
    <description>The latest articles on DEV Community by Thesi (@thecodingthesi).</description>
    <link>https://dev.to/thecodingthesi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1257521%2F1d83870d-7c08-4896-9d21-9868920e92c3.jpeg</url>
      <title>DEV Community: Thesi</title>
      <link>https://dev.to/thecodingthesi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thecodingthesi"/>
    <language>en</language>
    <item>
      <title>Your journey to become a Docker Hero starts today! 🚀🚀</title>
      <dc:creator>Thesi</dc:creator>
      <pubDate>Wed, 04 Dec 2024 14:48:18 +0000</pubDate>
      <link>https://dev.to/thecodingthesi/your-journey-to-become-a-docker-hero-starts-today-16a5</link>
      <guid>https://dev.to/thecodingthesi/your-journey-to-become-a-docker-hero-starts-today-16a5</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/code42cate" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F461127%2F034233c4-ba6e-473c-8a8d-783831764a10.jpeg" alt="code42cate"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/code42cate/advent-of-docker-day-4-your-first-container-bhj" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Day 4: Your first Container&lt;/h2&gt;
      &lt;h3&gt;Jonas Scholz ・ Dec 4 '24&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#docker&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#devops&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>How to Dockerize a Flask App 🐳</title>
      <dc:creator>Thesi</dc:creator>
      <pubDate>Sat, 21 Sep 2024 17:15:45 +0000</pubDate>
      <link>https://dev.to/thecodingthesi/how-to-dockerize-a-flask-app-2fho</link>
      <guid>https://dev.to/thecodingthesi/how-to-dockerize-a-flask-app-2fho</guid>
      <description>&lt;p&gt;Dockerizing a Flask app is a great way to make your app ready to be deployed on any cloud platform. Luckily, it's super easy to do. Lets get started!&lt;/p&gt;

&lt;p&gt;The absolute easiest way to dockerize a flask app is to use the &lt;code&gt;Dockerfile&lt;/code&gt; that we've provided below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;pip3 &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt

&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Buuuut, there is a lot of room for improvement. Lets go over some improvements and next steps together&lt;/p&gt;

&lt;h2&gt;
  
  
  Improvements
&lt;/h2&gt;

&lt;p&gt;These are all super easy to do and will make your life easier, trust me!&lt;/p&gt;

&lt;h3&gt;
  
  
  Use a better python base image
&lt;/h3&gt;

&lt;p&gt;The base image that we used is the latest version of python, which is great, but we can do better. Generally, you want to use specific versions of your base images to prevent any breaking changes.&lt;br&gt;
Additionally, the normal &lt;code&gt;python:3&lt;/code&gt; image is huge at 1GB! We can do better, by simply using &lt;code&gt;python:3.11-alpine3.20&lt;/code&gt; for example. This image is only 64MB big!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.11-alpine3.20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Improve the caching
&lt;/h3&gt;

&lt;p&gt;Right now we copy everything into the image at once. While this is super easy, it's not very efficient. We can do better by copying the requirements first, installing the dependencies and then copying the rest of the app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; requirements.txt requirements.txt&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;pip3 &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will allow the dependencies to be cached and not re-installed on every build! Subsequent builds will be a lot faster 🚀.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use a working directory
&lt;/h3&gt;

&lt;p&gt;This is really more of a personal preference, but I prefer to have the working directory set to &lt;code&gt;/app&lt;/code&gt;. This is the standard working directory for most apps and it's easy to remember.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You dont just put all of your app code into your documents folder, do you? So why would you do that in a Docker image? :D&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Dockerfile
&lt;/h2&gt;

&lt;p&gt;The final Dockerfile should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.11-alpine3.20&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; requirements.txt requirements.txt&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;pip3 &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt

&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simply build it using &lt;code&gt;docker build . -t flask-app&lt;/code&gt; and run it using &lt;code&gt;docker run -p 5050:5050 flask-app&lt;/code&gt;! 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;At this poing you probably want to either push it to a Docker Registry or host it somewhere.&lt;/p&gt;

&lt;p&gt;I work for &lt;a href="https://sliplane.io?utm_source=dockerize-flask" rel="noopener noreferrer"&gt;Sliplane&lt;/a&gt;, a Docker hosting platform that makes it super easy to host your Docker apps. Check it out, the first 2 days are on me:)&lt;/p&gt;

</description>
      <category>docker</category>
      <category>python</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
