DEV Community

Gias Uddin
Gias Uddin

Posted on • Edited on

How to Dockerize Django Project in 2 minutes

To run a Django project in Docker, you will need to have Docker installed on your system. You can then create a Dockerfile for your Django project that specifies the necessary dependencies and commands for running the project.

Here is an example of a **Dockerfile **for a Django project:

# specify the base image
FROM python:3.7

# set the working directory
WORKDIR /app

# copy the requirements file
COPY requirements.txt /app/

# install dependencies
RUN pip install -r requirements.txt

# copy the rest of the project files
COPY . /app/

# expose the port that the Django application will run on
EXPOSE 8000

# run the Django application
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Enter fullscreen mode Exit fullscreen mode

Once you have created this Dockerfile, you can build your Docker image by running the following command:

docker build -t <image-name> .
Enter fullscreen mode Exit fullscreen mode

This will create a Docker image with the specified name () using the instructions in the Dockerfile.

To run the Django project in a Docker container, you can then use the following command:

Copy code

docker run -p 8000:8000 <image-name>
Enter fullscreen mode Exit fullscreen mode

This will run the Django application in a Docker container using the specified image and map the container's port 8000 to the host's port 8000, allowing you to access the application at

http://localhost:8000
Enter fullscreen mode Exit fullscreen mode

Thank you for reading my article! If you enjoyed it and would like to support my work, please consider buying me a coffee at Buy Me a Coffee. You can also learn more about me and my work by visiting my Giasuddin Bio and following me on LinkedIn and Twitter. Thank you for your support!

Top comments (0)