<?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: Tanay Jain</title>
    <description>The latest articles on DEV Community by Tanay Jain (@tj2905).</description>
    <link>https://dev.to/tj2905</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%2F3843172%2Fbca77b7a-7dce-4561-a15a-e19f299d5df6.jpeg</url>
      <title>DEV Community: Tanay Jain</title>
      <link>https://dev.to/tj2905</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tj2905"/>
    <language>en</language>
    <item>
      <title>From Zero to Deployment: Dockerizing a Flask + PostgreSQL App on AWS</title>
      <dc:creator>Tanay Jain</dc:creator>
      <pubDate>Sun, 29 Mar 2026 18:56:16 +0000</pubDate>
      <link>https://dev.to/tj2905/from-zero-to-deployment-dockerizing-a-flask-postgresql-app-on-aws-20go</link>
      <guid>https://dev.to/tj2905/from-zero-to-deployment-dockerizing-a-flask-postgresql-app-on-aws-20go</guid>
      <description>&lt;p&gt;When I started learning Docker, I had no idea I’d end up deploying a real application on a cloud server within the same month.&lt;/p&gt;

&lt;p&gt;It ended up changing how I think about building software.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Idea
&lt;/h2&gt;

&lt;p&gt;I didn’t want to build just another static project.&lt;/p&gt;

&lt;p&gt;I wanted:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A real backend
&lt;/li&gt;
&lt;li&gt;A real database
&lt;/li&gt;
&lt;li&gt;A real deployment
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I built a simple web app that tracks page visits and stores them in PostgreSQL.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python Flask (backend)
&lt;/li&gt;
&lt;li&gt;PostgreSQL (database)
&lt;/li&gt;
&lt;li&gt;Docker &amp;amp; Docker Compose
&lt;/li&gt;
&lt;li&gt;AWS EC2 (deployment)
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User (Internet)
   ↓
AWS EC2 Server
   ↓
Docker Engine
   ↓
Flask Container (Port 80)
   ↓ psycopg2
PostgreSQL Container
   ↓
Persistent Volume (pgdata)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Key Concepts I Implemented
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔹 Multi-container system
&lt;/h3&gt;

&lt;p&gt;Instead of running containers manually, I used Docker Compose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker compose up &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This starts the entire system in one command.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Environment variables (.env)
&lt;/h3&gt;

&lt;p&gt;No secrets inside the code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cleaner
&lt;/li&gt;
&lt;li&gt;Safer
&lt;/li&gt;
&lt;li&gt;Production-ready
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔹 Health checks
&lt;/h3&gt;

&lt;p&gt;Docker monitors the application continuously.&lt;br&gt;&lt;br&gt;
If Flask stops responding, the container is marked as unhealthy.&lt;/p&gt;


&lt;h3&gt;
  
  
  🔹 Auto-restart
&lt;/h3&gt;

&lt;p&gt;Using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;restart&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;always&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a container crashes, Docker automatically restarts it.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Optimized Dockerfile
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Used &lt;code&gt;python:3.10-slim&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Cleared apt cache after install
&lt;/li&gt;
&lt;li&gt;Used &lt;code&gt;--no-cache-dir&lt;/code&gt; for pip
&lt;/li&gt;
&lt;li&gt;Optimized layer ordering
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt; Image size reduced significantly (~300MB → ~160MB)&lt;/p&gt;




&lt;h2&gt;
  
  
  Biggest Challenge
&lt;/h2&gt;

&lt;p&gt;Connecting Flask to PostgreSQL inside Docker.&lt;/p&gt;

&lt;p&gt;The key realization:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Containers communicate using service names, not IP addresses.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_HOST=db
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Docker internally resolves &lt;code&gt;db&lt;/code&gt; to the PostgreSQL container.&lt;br&gt;&lt;br&gt;
Once this clicked, the setup became much clearer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;

&lt;p&gt;I deployed the app on AWS EC2.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Launch EC2 instance
&lt;/li&gt;
&lt;li&gt;Install Docker
&lt;/li&gt;
&lt;li&gt;Clone project
&lt;/li&gt;
&lt;li&gt;Run Docker Compose
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The application was then accessible via a public IP.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;p&gt;Docker is not just about containers.&lt;/p&gt;

&lt;p&gt;It’s about building systems that are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reproducible
&lt;/li&gt;
&lt;li&gt;Isolated
&lt;/li&gt;
&lt;li&gt;Self-healing
&lt;/li&gt;
&lt;li&gt;Easy to deploy
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/tj2905/flask-docker-app" rel="noopener noreferrer"&gt;https://github.com/tj2905/flask-docker-app&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Docker Hub: &lt;a href="https://hub.docker.com/r/tanayjain29/flask-devops-app" rel="noopener noreferrer"&gt;https://hub.docker.com/r/tanayjain29/flask-devops-app&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;This project was my first real experience combining backend, database, and deployment into one system.&lt;/p&gt;

&lt;p&gt;If you're learning Docker, building and deploying even a small project like this gives much more clarity than just following tutorials.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>flask</category>
      <category>aws</category>
      <category>postgres</category>
    </item>
  </channel>
</rss>
