<?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: Mahesh Prajapati</title>
    <description>The latest articles on DEV Community by Mahesh Prajapati (@mahyess).</description>
    <link>https://dev.to/mahyess</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%2F508112%2Fb78556f6-713d-4b61-beb2-7324607d894f.jpeg</url>
      <title>DEV Community: Mahesh Prajapati</title>
      <link>https://dev.to/mahyess</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mahyess"/>
    <language>en</language>
    <item>
      <title>Django Admin Mazer - Custom Django-admin replacement</title>
      <dc:creator>Mahesh Prajapati</dc:creator>
      <pubDate>Thu, 24 Feb 2022 10:03:23 +0000</pubDate>
      <link>https://dev.to/mahyess/django-admin-mazer-custom-django-admin-replacement-33ke</link>
      <guid>https://dev.to/mahyess/django-admin-mazer-custom-django-admin-replacement-33ke</guid>
      <description>&lt;p&gt;I am currently working on a Django admin templates replacement app, named &lt;code&gt;django-admin-mazer&lt;/code&gt;. Available to install with &lt;code&gt;pip&lt;/code&gt; for your testing.&lt;/p&gt;

&lt;p&gt;The templates are taken from an open-source admin template available &lt;a href="https://zuramai.github.io/mazer/demo/index.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Installation process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;pip install django-admin-mazer&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add '&lt;code&gt;django_admin_mazer&lt;/code&gt;' in your &lt;code&gt;INSTALLED_APPS&lt;/code&gt; and you are good to go.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/mahyess/django-admin-mazer" rel="noopener noreferrer"&gt;https://github.com/mahyess/django-admin-mazer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some screenshots taken while in development:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy1xqmtoqgoz5m9yugf7s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy1xqmtoqgoz5m9yugf7s.png" alt="Home Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmiagqlfsb7tden7p6aoy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmiagqlfsb7tden7p6aoy.png" alt="App Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqihnqz7gcveotorb6r09.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqihnqz7gcveotorb6r09.png" alt="Login Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnajnyiqqp8yjf7n6b5bu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnajnyiqqp8yjf7n6b5bu.png" alt="Model Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5x0j3nruc8jehuel0tnv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5x0j3nruc8jehuel0tnv.png" alt="Update Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be warned, this project is bootstrapped in a short amount of time, so expect some glitches here and there. So, there are unfinished tasks that I may not have found out just yet. &lt;/p&gt;

&lt;p&gt;Please feel free to point out problems, or even contribute to the project.&lt;/p&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/mahyess/django-admin-mazer" rel="noopener noreferrer"&gt;https://github.com/mahyess/django-admin-mazer&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Docker-compose-ing a Django App - for complete starters</title>
      <dc:creator>Mahesh Prajapati</dc:creator>
      <pubDate>Mon, 31 Jan 2022 14:08:18 +0000</pubDate>
      <link>https://dev.to/mahyess/docker-compose-ing-a-django-app-for-complete-starters-26c</link>
      <guid>https://dev.to/mahyess/docker-compose-ing-a-django-app-for-complete-starters-26c</guid>
      <description>&lt;p&gt;In the earlier post, in which I described about &lt;a href="https://dev.to/mahyess/dockerizing-a-django-app-for-starters-3a5b"&gt;writing a simple Dockerfile for a Django App.&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;We will pickup where we left off earlier. If you are completely new to Docker, I recommend checking &lt;a href="https://dev.to/mahyess/dockerizing-a-django-app-for-starters-3a5b"&gt;the previous post&lt;/a&gt; first.&lt;/p&gt;

&lt;p&gt;The starter code that we are using for this post is &lt;a href="https://github.com/mahyess/django-dockered/tree/1-base-docker"&gt;available in GitHub&lt;/a&gt; if you want to follow along.&lt;/p&gt;

&lt;p&gt;Let's see how the file structure looks before we start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── Dockerfile
├── manage.py
├── README.md
├── requirements.txt
└── main
    ├── asgi.py
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are following from the previous post, you will notice I have renamed the 'main' project folder from todo to main. It's because I want to scale this tutorial series to use as a starting template for future projects. So I felt it's important to keep the folders' name as generic as they can be.&lt;/p&gt;

&lt;p&gt;The folder structure shouldn't seem to be too confusing as they are not complicated to understand.&lt;/p&gt;

&lt;p&gt;Let's go forward. First of all, create a directory in project root called &lt;code&gt;app&lt;/code&gt; and move all existing contents to the &lt;code&gt;app&lt;/code&gt; folder, so the folder structure now looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── app
│   ├── Dockerfile
│   ├── entrypoint.sh
│   ├── main
│   │   ├── asgi.py
│   │   ├── __init__.py
│   │   ├── settings.py
│   │   ├── urls.py
│   │   └── wsgi.py
│   ├── manage.py
│   └── requirements.txt
└── README.md

3 directories, 12 files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why do this? It's because we are incorporating &lt;code&gt;docker-compose&lt;/code&gt; which by its nature, allows us to manage multiple tools for our project, &lt;code&gt;django&lt;/code&gt; being one of them. Each of those tools and their configs should go to their respective directory for clear code and readability. &lt;/p&gt;

&lt;p&gt;Now, let's create a &lt;code&gt;docker-compose.yml&lt;/code&gt; file at the root directory, which now contains the &lt;code&gt;app&lt;/code&gt; directory and write the following lines of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "3.8"

services:
  app:
    build:
      context: ./app
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - ./app:/app
    ports:
      - "8000:8000"
    env_file:
      - ./app/.env
    environment:
      - DEBUG=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through the code and see what's happening&lt;br&gt;
1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "3.8"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We want to use &lt;code&gt;docker-compose&lt;/code&gt; version 3.8. How does this versioning matter? That's a lot of complex topics for this post, but if you want to know more, you can check &lt;a href="https://docs.docker.com/compose/compose-file/"&gt;official docker website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We want to list the '&lt;code&gt;tools&lt;/code&gt;' as mentioned earlier as array items within the services.&lt;/p&gt;

&lt;p&gt;3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  app:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each of the '&lt;code&gt;tools&lt;/code&gt;' needs their own name as recognition. &lt;code&gt;app&lt;/code&gt; is just a generic name for the &lt;code&gt;django&lt;/code&gt; container. You can put anything instead of &lt;code&gt;app&lt;/code&gt; like &lt;code&gt;django&lt;/code&gt;, &lt;code&gt;server&lt;/code&gt; or even &lt;code&gt;labrador&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    build:
      context: ./app
      dockerfile: Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we know, each '&lt;code&gt;tool&lt;/code&gt;' or &lt;code&gt;container&lt;/code&gt; in docker languages, needs to build before we run. We learnt that in the previous post as well. &lt;code&gt;docker-compose&lt;/code&gt; needs to know which folder to look for to build the container &lt;code&gt;app&lt;/code&gt;. So, naturally, we put all the files related to the &lt;code&gt;app&lt;/code&gt; container into &lt;code&gt;app&lt;/code&gt; folder and gave the context name to &lt;code&gt;./app&lt;/code&gt;, as in &lt;code&gt;app&lt;/code&gt; folder from where &lt;code&gt;docker-compose.yml&lt;/code&gt; file is located.&lt;/p&gt;

&lt;p&gt;At the same time, it also asks for &lt;code&gt;Dockerfile&lt;/code&gt; location. So the name and location, relative to the folder provided in &lt;code&gt;context&lt;/code&gt;. We may want to have multiple &lt;code&gt;Dockerfile&lt;/code&gt;s later on, so it is convenient to have them in easy-to-remember place&lt;/p&gt;

&lt;p&gt;5.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    command: python manage.py runserver 0.0.0.0:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you understand &lt;code&gt;Django&lt;/code&gt;, this is just a standard &lt;code&gt;run&lt;/code&gt; command which we want to do when we start the server later on.&lt;/p&gt;

&lt;p&gt;6.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    volumes:
      - ./app:/app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;volumes&lt;/code&gt; mapping allows us to map local folders to folders inside the container. If you look into &lt;code&gt;Dockerfile&lt;/code&gt;, we created a folder named &lt;code&gt;app&lt;/code&gt;. The folder inside the container and local system stay synchronized with this command. It also triggers hot reloading of server whenever we change something in local system, so it's very important to keep it on while debugging. Else, we will have to restart the server on every code change.&lt;/p&gt;

&lt;p&gt;7.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    ports:
      - "8000:8000"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like the previous post, we want to map our local port 8000 to container's port 8000 to access the server. &lt;/p&gt;

&lt;p&gt;With this, you can remove the lines 7. &lt;code&gt;EXPOSE 8000&lt;/code&gt; and 8. &lt;code&gt;CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]&lt;/code&gt; Since, both of them are now managed by &lt;code&gt;docker-compose&lt;/code&gt; herein. &lt;/p&gt;

&lt;p&gt;8.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    env_file:
      - ./app/.env
    environment:
      - DEBUG=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both &lt;code&gt;env_file&lt;/code&gt; and &lt;code&gt;environment&lt;/code&gt; can be used to set environment variables to the container. &lt;code&gt;environment&lt;/code&gt;s are preferred when the variables are public, whereas &lt;code&gt;env_file&lt;/code&gt;s which are usually &lt;code&gt;git-ignored&lt;/code&gt;, can be used to set private environment variables like &lt;code&gt;secret-keys&lt;/code&gt;, &lt;code&gt;tokens&lt;/code&gt; and even &lt;code&gt;passwords&lt;/code&gt;. We will look into how to use them later on. &lt;/p&gt;

&lt;p&gt;For now, lets go to the terminal and hit up&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything went fine, you may now see &lt;code&gt;Successfully built&lt;/code&gt; in the terminal. &lt;/p&gt;

&lt;p&gt;So, we may now fire up the server by running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We should now be presented with this beautiful screen when we navigate to &lt;code&gt;localhost:8000&lt;/code&gt; in our browser.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f7kapyW1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53vgda3gdpj40ozcqh65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f7kapyW1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53vgda3gdpj40ozcqh65.png" alt="Django Starting Page" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all it takes to run our &lt;code&gt;django&lt;/code&gt; project with &lt;code&gt;docker-compose&lt;/code&gt;. As simple as it can get.&lt;/p&gt;

&lt;p&gt;All the code is available in &lt;a href="https://github.com/mahyess/django-dockered/tree/2-base-docker-compose"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Up next, we will add &lt;code&gt;postgres&lt;/code&gt; database and &lt;code&gt;nginx&lt;/code&gt; reverse proxy to the setup and find-out how docker-compose systems can be scaled up.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>docker</category>
      <category>python</category>
    </item>
    <item>
      <title>Dockerizing a Django App - for complete starters</title>
      <dc:creator>Mahesh Prajapati</dc:creator>
      <pubDate>Wed, 19 Jan 2022 12:21:32 +0000</pubDate>
      <link>https://dev.to/mahyess/dockerizing-a-django-app-for-starters-3a5b</link>
      <guid>https://dev.to/mahyess/dockerizing-a-django-app-for-starters-3a5b</guid>
      <description>&lt;p&gt;As starters, the term docker can be quite daunting and may seem a big cliff to overcome but it shouldn't be as such.&lt;/p&gt;

&lt;p&gt;The vast amounts of tutorials covering a lot of information at once, doesn't help the starters, speaking from personal experience. That's why, this post is a single step towards the complete new world of docker. So, let's begin.&lt;/p&gt;

&lt;p&gt;First thing first, you need to have a existing Django project that you are willing to Dockerize.&lt;/p&gt;

&lt;p&gt;I have created a new Django project for this very purpose and going to use it as a starting template. Let's see files that are here inside this folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── db.sqlite3
├── manage.py
├── requirements.txt
└── todo
    ├── asgi.py
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a complete boilerplate, when run the server with &lt;code&gt;python manage.py runserver&lt;/code&gt;, we are presented with our starting page.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f7kapyW1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53vgda3gdpj40ozcqh65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f7kapyW1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53vgda3gdpj40ozcqh65.png" alt="Django Starting Page" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far, so good.&lt;/p&gt;

&lt;p&gt;Let's create a file named Dockerfile in the root directory. The files tree needs to look like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── db.sqlite3
├── Dockerfile
├── manage.py
├── requirements.txt
└── todo
    ├── asgi.py
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's quote what Dockerfile is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is where we put the commands to build our image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM python:3.10

RUN mkdir /app

COPY requirements.txt /app/

WORKDIR /app

RUN pip install -r requirements.txt

COPY . /app/

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through these commands one by one.&lt;/p&gt;

&lt;p&gt;1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM python:3.10-slim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are using &lt;code&gt;python:3.10-slim&lt;/code&gt; as our base image from which we build our image. We can use &lt;code&gt;python:3.10&lt;/code&gt; but it will generate larger build file, which we should be trying to reduce. Also, we can use &lt;code&gt;python:3.10-alpine&lt;/code&gt; which reduces the size even further, but this will require extra care from our end. That's a topic for some other time. If you are interested in knowing further, you can go through &lt;a href="https://hub.docker.com/_/alpine"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN mkdir /app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is pretty straight-forward. It creates a new directory called &lt;code&gt;app&lt;/code&gt; in root directory of the image.&lt;/p&gt;

&lt;p&gt;3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;COPY requirements.txt /app/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It copies the &lt;code&gt;requirements.txt&lt;/code&gt; file from our project to the directory we just created. If you don't have this file yet, you can create one by entering the command &lt;code&gt;pip freeze &amp;gt; requirements.txt&lt;/code&gt; which gets all packages that are currently installed in our django project and writes them into the said file.&lt;/p&gt;

&lt;p&gt;4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WORKDIR /app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It sets the current working directory to the directory we created. In other words, we &lt;code&gt;cd&lt;/code&gt;ed to this directory. Any commands we enter from herein are triggered from this directory.&lt;/p&gt;

&lt;p&gt;5.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The image we used from &lt;code&gt;line 1&lt;/code&gt;, &lt;code&gt;python:3.10-slim&lt;/code&gt; as pip installed into it by default. So we can run any &lt;code&gt;pip&lt;/code&gt; commands in the image. This command installs all the packages that we had installed in our local system previously.&lt;/p&gt;

&lt;p&gt;6.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;COPY . /app/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similar to &lt;code&gt;line 3&lt;/code&gt;, but now we copy all files and folders in the local system into the image. Now, why didn't we did this in &lt;code&gt;line 3&lt;/code&gt; itself? If you wondered, that's good. It's because &lt;code&gt;docker&lt;/code&gt; caches all the commands while building the image, so if we haven't changes &lt;code&gt;requirements.txt&lt;/code&gt; further down the line in future, all commands from &lt;code&gt;1-5&lt;/code&gt; aren't triggered again. Else, even if there aren't any changes in packages, but have changes in our project, &lt;code&gt;docker&lt;/code&gt; will unnecessarily installs all the packages again.&lt;/p&gt;

&lt;p&gt;7.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EXPOSE 8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are almost done. It &lt;code&gt;exposes&lt;/code&gt; the port 8000 to "outside world" from image. Since we are going to run Django in port 8000, this is a gateway to the server we are going to run later.&lt;/p&gt;

&lt;p&gt;8.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, it runs the command &lt;code&gt;python manage.py runserver 0.0.0.0:8000&lt;/code&gt; inside the image. That means, our server will now be up and running.&lt;/p&gt;

&lt;p&gt;We have completed writing a very basic &lt;code&gt;Dockerfile&lt;/code&gt; that works. Now, head up to the terminal and enter the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t todo/latest .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's wait for some time as docker builds our image. If you are wondering what's &lt;code&gt;todo/latest&lt;/code&gt;, its a tag name. You can put anything as you want or even skip it to just run &lt;code&gt;docker build .&lt;/code&gt;, but we will have to search for our image by going to through a list of images built in the system by going through &lt;code&gt;docker ps&lt;/code&gt;. Let's not go out of our way for now. If you are interested, you can certain try it by yourself.&lt;/p&gt;

&lt;p&gt;So, after waiting a couple of minutes, or seconds, depending on several factors, to complete the build, let's trigger the final command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -p 8000:8000 todo/latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command runs the &lt;code&gt;CMD&lt;/code&gt; that we have provided in the Dockerfile. As for &lt;code&gt;8000:8000&lt;/code&gt;, we are binding our local port &lt;code&gt;8000&lt;/code&gt; to the image's port &lt;code&gt;8000&lt;/code&gt;. If you wish, you can put &lt;code&gt;80:8000&lt;/code&gt;, so it binds to local port &lt;code&gt;80&lt;/code&gt; to the image's port.&lt;/p&gt;

&lt;p&gt;If everything goes well, your terminal should get a normal Django server log. For me, it's&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;╰─ docker run -p 8000:8000 todo/latest
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
January 19, 2022 - 11:55:15
Django version 4.0.1, using settings 'todo.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check our browser for confirmation. We should be presented again with this beautiful page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--f7kapyW1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53vgda3gdpj40ozcqh65.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f7kapyW1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53vgda3gdpj40ozcqh65.png" alt="Django Starting Page" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations, you have successfully "Dockerize" your Django application. &lt;/p&gt;

&lt;p&gt;As for the migrations warnings, you can add a line &lt;code&gt;RUN python manage.py migrate&lt;/code&gt; after &lt;code&gt;line 6&lt;/code&gt; and before &lt;code&gt;line 8&lt;/code&gt;, and build again.&lt;/p&gt;

&lt;p&gt;This is a very basic Dockerfile as mentioned. I want it to be understood by a complete beginner so haven't included a number of "gotcha"s to the Dockerfile, they can be learnt as we go and code. &lt;/p&gt;

&lt;p&gt;The complete code can be found in my &lt;a href="https://github.com/mahyess/django-dockered"&gt;GitHub&lt;/a&gt;. Feel free to check it out, if you are having any problems.&lt;/p&gt;

</description>
      <category>django</category>
      <category>docker</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
