<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Muthuraman on Medium]]></title>
        <description><![CDATA[Stories by Muthuraman on Medium]]></description>
        <link>https://medium.com/@A2Z-technology?source=rss-75cd427ca3bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GG43ymjNMA3B3ibXynN1Rw.jpeg</url>
            <title>Stories by Muthuraman on Medium</title>
            <link>https://medium.com/@A2Z-technology?source=rss-75cd427ca3bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:44:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@A2Z-technology/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Stop Fighting with Deployment: Dockerize Your Django Application- A Complete Guide for Beginners]]></title>
            <link>https://medium.com/@A2Z-technology/stop-fighting-with-deployment-dockerize-your-django-application-a-complete-guide-for-beginners-e7e24566c070?source=rss-75cd427ca3bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7e24566c070</guid>
            <dc:creator><![CDATA[Muthuraman]]></dc:creator>
            <pubDate>Tue, 05 Nov 2024 07:24:47 GMT</pubDate>
            <atom:updated>2024-11-05T11:26:57.291Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*1bWJZ17HvnNVJMhV-zmP4A.png" /><figcaption>django with docker</figcaption></figure><p>Imagine this: you’ve built a robust Django backend, but now the front-end web and mobile developers need to replicate your setup to get everything working on their end. Every time there’s an update, deployment becomes a headache — configuring resources on the server, aligning environments, and ensuring nothing breaks. This is where Docker steps in as a game-changer! By containerizing your application, Docker makes it incredibly easy to package everything up and ensure it runs smoothly, no matter where it’s deployed.</p><p>In this article, we’ll walk you through creating your very first Dockerfile to deploy a Python Django application. Perfect for beginners, this guide will take you step-by-step through containerizing your Django project, so you can ensure reliable, consistent deployments across all environments. You’ll learn the Docker basics, set up a Dockerfile, and configure it to make your Django app deployment-ready. Let’s dive in and make your development process simpler and more efficient with Docker!</p><p><strong>What is Django?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqSEdaspCgydiNyyjeWTKA.png" /><figcaption>source: google</figcaption></figure><p>Django is a high-level Python web framework that simplifies web application development by promoting rapid development and clean design. It follows the Model-View-Template (MVT) architecture, separating data management, business logic, and presentation. Key features include a built-in admin interface, an intuitive Object-Relational Mapping (ORM) system for database interactions and robust security protections against common vulnerabilities. Django is known for its scalability, making it suitable for small and large applications. Overall, it provides the tools to build secure, maintainable web applications quickly and efficiently.</p><p><strong>Why Docker?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*rjYJOimJnzZM0T9O6Qb7Mw.png" /><figcaption>Docker</figcaption></figure><p>Docker is a platform that simplifies application development and deployment by containerizing applications and their dependencies. It ensures consistency across different environments, allowing the same code to run reliably on local machines, testing environments, and production. Docker containers are lightweight, isolated, and efficient, offering easy scalability, better resource management, and enhanced security. It also streamlines the CI/CD pipeline, making building, testing, and deploying applications consistently easier. Docker’s portability and isolation make it a preferred choice for modern microservices and cloud-native development.</p><ol><li><strong>Creating Django Application:</strong></li></ol><blockquote>First, ensure you have Python and pip installed for creating virtual environment Then, you can install Django using pip. Open your terminal or command prompt and run:</blockquote><p><strong>Creating Virtual environment</strong></p><blockquote>Working with separate virtualenv for each project is the best practice</blockquote><pre>py -m venv venv</pre><p><strong>Activate the Virtualenv</strong></p><pre>venv\Scripts\activate.bat</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*eCmeQVWoGMhrLAmPDsRRKA.png" /><figcaption>Command Prompt</figcaption></figure><blockquote>(venv) indicate that virtual environment is activated in your terminal</blockquote><p><strong>Install Django</strong></p><pre>pip install Django</pre><p><strong>Create Django project:</strong></p><p>Once Django is installed, you can create a new project using the following command:</p><pre>django-admin startproject myFoodapp</pre><p><strong>Folder structure:</strong></p><pre>myFoodapp <br>   manage.py <br>   myFoodapp/ <br>       __init__.py <br>       asgi.py <br>       settings.py <br>       urls.py <br>       wsgi.py</pre><p><strong>Navigate to the project directory:</strong></p><pre>cd myFoodapp</pre><p><strong>Create a Django App:</strong></p><p>Django apps are structured to separate logic and support the model-view-controller pattern. Each app has its database, URLs, HTML templates, and static files</p><p>In Django, projects are made up of apps. To create an app, run the following command</p><pre>python manage.py startapp kitchenApp</pre><pre>myFoodapp <br>   manage.py <br>   myFoodapp/ <br>   kitchenApp / <br>     migrations/ <br>       __init__.py <br>     __init__.py <br>     admin.py <br>     apps.py <br>     models.py <br>     tests.py <br>     views.py</pre><p><strong>Add an App to your project:</strong></p><p><em>Open </em><strong><em>myFoodapp</em></strong><em>/settings.py and add your app:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*cx1K39ZVTcXObtSbnnoNkA.png" /><figcaption>myFoodapp -&gt; myFoodapp -&gt; settings.py</figcaption></figure><p><strong>Create views file:</strong></p><p>This views file can be found in all created apps and is especially used for implementing our business logic. Essentially, the code within this file will execute whenever our endpoint is hit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*Jspn9z-3P0gNw1WBEmgDPQ.png" /><figcaption>myFoodapp/kitchenApp/views.py</figcaption></figure><p><strong>Map the view to a URL:</strong></p><p>create a new file called <strong>urls.py</strong> in the <strong>kitchenApp </strong>directory and define the URL patterns:</p><pre>myFoodapp <br>   manage.py <br>   myFoodapp/ <br>   kitchenApp / <br>     migrations/ <br>       __init__.py <br>     __init__.py <br>     admin.py <br>     apps.py <br>     models.py <br>     tests.py <br>     views.py<br>     urls.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*WZeZ1fxTX9R4QLcva2n1pg.png" /><figcaption>myFoodapp/kitchenApp/urls.py</figcaption></figure><p><strong>Redirect the project URL to the app URL</strong></p><p>Now, include the app’s URL patterns in the project’s main urls.py file located in the <strong>myFoodapp</strong> directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*a3aI9flzObB_piqlX3L-Vg.png" /><figcaption>myFoodapp/myFoodapp/urls.py</figcaption></figure><p><strong>Migrate the database:</strong></p><p>Django supports managing the database schema smoothly and consistently across different environments. using below commands</p><p>first, prepare migration files that reflect these changes in the database</p><pre>python manage.py makemigrations</pre><p>at last, make the changes to the database using</p><pre>python manage.py migrate</pre><p><strong>Run the Server:</strong></p><p>Now run the server without the docker</p><pre>python manage.py runserver</pre><p><strong>Test Your App</strong></p><p>Open your browser and go to <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a> You should see “Home page..” displayed on the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5t8yxtbO5Ufa73-1fTY-g.png" /><figcaption>Google Chrome</figcaption></figure><p><strong>2. Create Dockerfile:</strong></p><p>let&#39;s containerize our Django application by writing dockerfile in the corresponding directory</p><pre>myFoodapp <br>   manage.py <br>   myFoodapp/ <br>   kitchenApp / <br>   requirements.txt<br>   Dockerfile</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*USr63Tp53jOLL1ejHCLStg.png" /></figure><p>explanation:</p><pre>FROM python:3.11 <br>                 =&gt; Sets Python 3.11 as the base image.<br><br>WORKDIR /app <br>                 =&gt; Sets the working directory to /app.<br><br>COPY . . <br>                 =&gt; Copies all files into the /app directory in the container.<br><br>RUN pip install -r requirements.txt <br>                 =&gt; Installs dependencies.<br><br>RUN python manage.py makemigrations &amp;<br>RUN python manage.py migrate <br>                 =&gt; Prepares and applies database migrations.<br><br>EXPOSE 8000 <br>                 =&gt; Exposes port 8000 for external access.<br><br>CMD [&quot;python&quot;,&quot;manage.py&quot;,&quot;runserver&quot;,&quot;0.0.0.0:8000&quot;] <br>                 =&gt; Runs the Django app on port 8000.</pre><p>once the dockerfile is written open the terminal and build the image using the below given comments</p><pre>docker build -t foodapp .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWzJTRNwgdjJIMs1fDyR5A.png" /><figcaption>Command Prompt</figcaption></figure><p>let&#39;s check whether the image is created or not by listing the available images</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*j6JDtXmBeVjnPKDyeBWR_g.png" /><figcaption>Command Prompt</figcaption></figure><p>From the image list, we can see that the “foodapp” image has been successfully created.</p><p>Now, let’s run the “foodapp” image by creating a container named “doc” and assigning port 8000 locally. Use the following command:</p><pre>docker run -idt --name doc -p 8000:8000 foodapp</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3P7GS-bFFjDZelVyO2Fdrg.png" /><figcaption>Command Prompt</figcaption></figure><p>list all running container</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kR1V07og0H4efY4n65WMpA.png" /><figcaption>Command Prompt</figcaption></figure><p>Open your browser and navigate to localhost:8000 to verify that Django is running successfully in the Docker container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9njNNwO071Mtg2bKwsKyBA.png" /><figcaption>Google Chrome</figcaption></figure><h3>Conclusion</h3><p>Congratulations on containerizing your Django application! You’ve now essentials of setting up a Dockerfile, building a Docker image, and running your app in a Docker container. By following these steps, you’ve ensured that your Django application can run seamlessly across different environments, making deployment faster, more consistent, and less error-prone. Docker’s portability and efficiency streamline collaboration, allowing front-end, mobile, and back-end teams to work with a consistent setup.</p><p>With these skills, you’re ready to explore more advanced Docker features, like using Docker Compose for multi-container applications or integrating Docker into your CI/CD pipeline.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7e24566c070" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>