How to Dockerize Django Project in 2 minutes

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"]

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

docker build -t <image-name> .

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>

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

Thanks for reading