To establish a setup for running Django in Docker using Docker Compose, you can follow these steps:
$ django-admin startproject myproject
Dockerfile
in the project's root directory.FROM python:3.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
docker-compose.yml
file in the project's root directory.version: '3'
services:
db:
image: postgres
environment:
POSTGRES_USER: myprojectuser
POSTGRES_PASSWORD: myprojectpassword
POSTGRES_DB: myprojectdb
volumes:
- postgres_data:/var/lib/postgresql/data/
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
volumes:
postgres_data:
requirements.txt
file in the project's root directory.Django==2.2
psycopg2==2.8.5
$ docker-compose up
Once the containers start, you can access the Django project at http://localhost:8000
.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-05 00:25:02 +0000
Seen: 13 times
Last updated: Jul 05 '23
What is the method to retrieve the JSON data from a column in SQL?
How to build an SQLAlchemy engine that uses psycopg3 as its foundation?
How can a string column be transformed into an array column in Django PostgreSQL migration?
Can we deploy a Python application with PostgreSQL on Heroku?
What is the process of developing two databases in a Django application using docker-compose?
How can a web application be developed to send distinct emails upon clicking the SUBMIT button?
How can Python import data from a centralized location?
How to analyze SQL using Python?
How can the SQL debug mode be activated in PostgreSQL version 15.2?
What is the procedure for using pg_restore on Windows with Docker?