Hello,
I have taken a project to Deploy Django and PostgreSQL on a couple of machines and I want to automate it with Docker,
I’ve found the following https://docs.docker.com/samples/django/ which lead me to
https://github.com/docker/awesome-compose/tree/master/official-documentation-samples/django/
However I’m having trouble adding all up to work properly
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hey there,
there are a couple of ways to go about what you want. In the link you provided, it’s stated you can create a Docker file and then add a configuration file which configures the services for you.
What I would do is to create the following
DockerFile
:In this Dockerfile, we start by using an official Python 3.9 slim image as the parent image. We then set the working directory to
/app
and copy therequirements.txt
file into the container. The parent image is modified by adding a newcode
directory. The parent image is further modified by installing the Python requirements defined in therequirements.txt
file.Next, we set environment variables for the PostgreSQL username, password, database name, and Django settings module. We install PostgreSQL and create the database using the
service
command and thesu
command to run the PostgreSQLpsql
command as thepostgres
user.We then copy the entire Django project into the container and run the
migrate
command to create the necessary tables in the database. We expose the default Django port 8000 and start the Django development server using theCMD
instruction.Note that you will need to modify this Dockerfile to match your specific Django and PostgreSQL configuration. For example, you will need to update the environment variables to match your PostgreSQL username, password, and database name, and update the
CMD
instruction to match the command used to start your Django server.Having said that, if you plan to deploy these projects on DigitalOcean, I can suggest you to check the https://www.digitalocean.com/products/managed-databases-postgresql)[Managed Databased DigitalOcean] offers.
https://docs.digitalocean.com/products/databases/postgresql/
Basically, it manages the Database for you so that you don’t have to worry about anything.