Setting up PostgreSQL database with a Django Docker application

  Рет қаралды 65,328

London App Developer

London App Developer

Күн бұрын

Пікірлер: 102
@saitaro
@saitaro 5 жыл бұрын
Super useful. That just worked with my old project. Thank you, Mark!
@matej-world
@matej-world 6 жыл бұрын
I just wanted to start learning Docker ... thanks, for this great intro!
@LondonAppDeveloper
@LondonAppDeveloper 5 жыл бұрын
You're welcome Matej! Glad you found it useful.
@aV5d9nlUBQ9
@aV5d9nlUBQ9 6 ай бұрын
Exactly what I needed. Thanks!
@LondonAppDeveloper
@LondonAppDeveloper 6 ай бұрын
Splendid.
@usamakaleem8378
@usamakaleem8378 3 жыл бұрын
Great but i was also expecting the pg_admin setup and also change user for postgres and password
@Zzzzzzzzzzzzzzzzzzzzr
@Zzzzzzzzzzzzzzzzzzzzr 6 жыл бұрын
Question wouldn’t all your previous data be lost as in the data you saved before you plugged in to the new database
@gabrieldjebbar5473
@gabrieldjebbar5473 4 жыл бұрын
You need to update in the requirements.txt Django==1.11.17 (or more), otherwise there is failure when building.
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Thank you
@WarrenBey
@WarrenBey Жыл бұрын
Amazing he was able to run a PG image without a PG password.
@tsoonamik
@tsoonamik 5 жыл бұрын
You are my superhero. Saved a lot of my time
@enricosaccheggiani3192
@enricosaccheggiani3192 3 жыл бұрын
Perfect , I have this problem. How to deploy this site not to localhost but hosting on a service like Google cloud Run. I am trying to deploy a site like this on a platform like digital Ocean or GCP but doesn't work. And more important, if I deploy this website where is the permanent storage? If I deploy my site on localhost the real database is on : volumes: - ./data/db:/var/lib/postgresql/data ./data/db but when it's deployed on a extern platform , where are effectly stored the data ? Thanks a lot if you can tell me the answer All the best regards
@giorgiberia
@giorgiberia 5 жыл бұрын
i din't change anything but docker compose fails saying can't open file 'src/profiles_project/manage.py': [Errno 2] No such file or directory
5 жыл бұрын
Same issue here
@SuperDiana997
@SuperDiana997 4 жыл бұрын
Replace the manage.py path to `./src/profiles_project/manage.py` when you are running migrations as well as the web server command in the docker-compose.yml file. Worked for me!
@peternjenga5045
@peternjenga5045 5 жыл бұрын
Worked perfectly! Thanks mate.
@nielsSavantKing
@nielsSavantKing Жыл бұрын
@London App Developer. So but it is better to omit de db container in production? Because I have read that it is not good to put a database in a docker container
@yvoncomeau
@yvoncomeau 6 жыл бұрын
Excellent demo. Thanks!
@nitishpatkar6190
@nitishpatkar6190 6 жыл бұрын
Could you perhaps also make a video to demonstrate how can we populate this freshly created database in the container with the data in existing database? I had an existing Django rest project set up with MySQL which already had some data saved. I decided to dockerize mmy project and followed both your tutorials. I can access my application at localhost. Now, I really would like to see how I could populate this database in the docker container with the data in my local MySQL database.
@LondonAppDeveloper
@LondonAppDeveloper 5 жыл бұрын
Hey Nitish, thanks for the comment, I'll definitely keep this in mind when making future content.
@JoseAlvarez-dl3hm
@JoseAlvarez-dl3hm 3 жыл бұрын
it totally work, amazing, thanks a lot, I will buy your udemy courses for sure.
@LondonAppDeveloper
@LondonAppDeveloper 3 жыл бұрын
Fantastic, thanks José.
@rajashreesekar1097
@rajashreesekar1097 6 жыл бұрын
Cool Video.. I was looking for this one. I wish you could have included where to find the data in postgres container.
@nielsSavantKing
@nielsSavantKing Жыл бұрын
HI, first you start your containers with docker-compose up. Then do docker ps -a . Then you will see the running containers. Then you will do a: docker exec -it nameContainer bash. Then you have to switch to the roler from your database: psql -U roleDatabase. And then with \d+ you will see all the tables in that database. and you can do just a select*from tableName and see all the data from that table.
@yashm05
@yashm05 4 жыл бұрын
loved your video, but im getting this error when i ran migrate commad django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known
@tylerdurden3073
@tylerdurden3073 4 жыл бұрын
same
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Maybe try running `docker-compose down` followed by `docker-compose up`... It could be that the database didn't start in time for some reason.
@globalassistance1050
@globalassistance1050 4 жыл бұрын
environment: - "POSTGRES_HOST_AUTH_METHOD=trust" in db service solved this for me
@ezadviper
@ezadviper 6 жыл бұрын
So now, how to connect to those databases in postgres container through pgadmin for backup, install plugins etc .. ?
@ahmedshawkat6101
@ahmedshawkat6101 4 жыл бұрын
there is an image for pgadmin you can configure it to run as a new image and bind it to a different port give me a second and ill show you how it is done
@ahmedshawkat6101
@ahmedshawkat6101 4 жыл бұрын
Here is the image link hub.docker.com/r/dpage/pgadmin4 Here is the code to set it up and running! pgadmin4: image: dpage/pgadmin4 ports: - 8050:80 environment: PGADMIN_DEFAULT_EMAIL: postgres@localhost PGADMIN_DEFAULT_PASSWORD: password
@Anyonelser
@Anyonelser 27 күн бұрын
Thank you 🎉
@gouthambolt
@gouthambolt 4 жыл бұрын
Took your rest api course. Was pretty boring but probably best course I have done. Help me get a ton of important skills and got lots of oppertunities. thank you! _/\_
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Lol thank you for taking our course. Sorry it was boring but glad to hear the boredom paid off in the end :)
@koustav2826
@koustav2826 3 жыл бұрын
Hello I'm facing an error: django.db.utils.operationalerror could not translate host name "db" to address: Temporary failure in name resolution I tried by adding links: and network: in docker compose file, but still it's showing the same
@minhajuddinansari561
@minhajuddinansari561 2 жыл бұрын
Try this. db: image: postgres environment: POSTGRES_HOST_AUTH_METHOD: trust
@aram69420
@aram69420 8 ай бұрын
@@minhajuddinansari561 Wow that helped a lot, thank you !
@snowpeak
@snowpeak 6 жыл бұрын
How do you deploy this to a VPS?
@saleee_6
@saleee_6 3 жыл бұрын
Thank you brother!
@jeetpatel2828
@jeetpatel2828 4 жыл бұрын
can you please do it with the mysql as well
@isaachatilima
@isaachatilima Жыл бұрын
Hi, I am in need of a tutorial for deploying a Django Docker app to Azure which will point to Azures PostgreSQL resource. Do you have that course?
@ashlingabrielrajan2496
@ashlingabrielrajan2496 4 жыл бұрын
Everything went well as per the tutorial . only when I run migrate I hit in to a trouble with psycopg2. Any ideas or suggestion? django core exception .Improperly configured: Error loading psycopg2 module :No module named 'psycopg2'
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Double check that this dependency is in your requirements.txt and try running `docker-compose build` again
@rhonaldjr
@rhonaldjr 5 жыл бұрын
Awesome, discovered just in time to migrate my db from sqlite to postgresql. Still stuck where docker spit out no such file or directory to run migrate command.
@kanakorn.h
@kanakorn.h 5 жыл бұрын
psycopg2 ---> IMHO pronounced "psycho pg two" LOL
@avtutube
@avtutube 4 жыл бұрын
Hi, can you create a Django using a mySQL database app into a Docker container. Great videos! Thank you.
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Should be more or less exactly the same, except you will use a MySQL docker image and configure Django for a mysql backend.
@36plain54
@36plain54 4 жыл бұрын
many many thanks!
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Most welcome!
@vinsmokearifka
@vinsmokearifka 4 жыл бұрын
thanks for the tutorial, but i got `django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres"`
@36plain54
@36plain54 4 жыл бұрын
I had a similar problem. Check to see if your database specifications in local 'settings.py' has the 'PASSWORD' field. If not, you'll need to define one (simply add 'PASSWORD': 'postgres' for now)
@vinsmokearifka
@vinsmokearifka 4 жыл бұрын
@@36plain54 thank you
@zbigniewsztobryn
@zbigniewsztobryn 3 жыл бұрын
Everything looks so smooth, but if it comes to publish my own project I get one error after another. I just go one by one but this one drives my crazy: django.db.utils.OperationalError: could not translate host name "dummy_endpoit" to address: Name does not resolve
@magodelviento
@magodelviento 6 жыл бұрын
How can you access to postgresql outside the container now? jus like a normal django app because now the host is 'db' .
@tommaso9839
@tommaso9839 4 жыл бұрын
When running docker-compose up, I get web_1 | python: can't open file 'src/profiles_project/manage.py': [Errno 2] No such file or directory byob-profiles-rest-api-docker_web_1 exited with code 2 even if my manage.py is in D:\...\byob-profiles-rest-api-docker\src\profiles_project how is this possible?
@vr9540
@vr9540 4 жыл бұрын
It might be fixed using python:3.6.12 version of python in the Dockerfile.
@nikitakurabtsev1222
@nikitakurabtsev1222 2 жыл бұрын
Thank you.
@nitishpatkar6190
@nitishpatkar6190 6 жыл бұрын
It helped me me a lot!
@jeremiahj2314
@jeremiahj2314 5 жыл бұрын
docker-compose up fails with'Error: Service 'web' failed to build unexpected EOF' any help would be appreciated. great vid.
@toniehubert
@toniehubert 3 жыл бұрын
Why are you in bieszczady mountains :O?
@LondonAppDeveloper
@LondonAppDeveloper 3 жыл бұрын
The photo is from Banff National Park (Canada).
@elenaperez6327
@elenaperez6327 4 жыл бұрын
Great video! I would love your advice. I have a django app which has a mysql db which I need to change over to postgres. Can I simply make the changes in the docker-compose.yml file or do I need to search for any mysql reference thoughout the whole app and change it to psql? Thank you for your help, I can't find much info about it online.
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Thanks! That depends... Is there a requirement to migrate data over or just create a fresh DB in PostgreSQL? If you need to migrate data, you'll probably need to run some SQL exports or potentially create a custom script for exporting/importing data. Otherwise you should be good to just switch the MySQL service to use Postgres and update your database backend in Django. Also, you would need to check your code for any hard dependencies on MySQL (for example, specific MySQL fields used in models, raw queries, etc...).
@thedemonlord9232
@thedemonlord9232 4 жыл бұрын
how can you access that database? when I add network_mode: bridge it fails building
@alkanecker9250
@alkanecker9250 6 жыл бұрын
Hi London, excellent video and very clear. I've followed all your steps exactly however I'm still running into the same error which brought me to your video; any call to manage.py or attempts to run the app with docker run into the following error: - django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known any idea why this might be? running on a linux server with: docker version == 18.03.1-ce django version == 1.11.1
@hilta7244
@hilta7244 4 жыл бұрын
Hi I got the same error, how did you fix it?
@minhajuddinansari561
@minhajuddinansari561 2 жыл бұрын
Try this. db: image: postgres environment: POSTGRES_HOST_AUTH_METHOD: trust
@bayramturgut5185
@bayramturgut5185 3 жыл бұрын
Hello, I have created django app and connect to Postgres. But I need help on some .. could I send the document that I need help.
@LondonAppDeveloper
@LondonAppDeveloper 3 жыл бұрын
Sorry but I don't have capacity to offer one to one debugging... I recommend posting on Stack Overflow or asking on community IRC.
@kingroc3651
@kingroc3651 4 жыл бұрын
How do you migrate the actual data in tables from previous sqlite to postgresql? I did't see this in your video.
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Hey yes that's not covered in the video. This would not be straightforward unfortunately. The easiest way might be to write a script that exports the tables to CSV, then write another script to import them from CSV files into PostgresSQL.
@ezequiasrocha3037
@ezequiasrocha3037 3 жыл бұрын
What is the version of Django you are using here?
@LondonAppDeveloper
@LondonAppDeveloper 3 жыл бұрын
Quite an old version (1.11) but the steps should be the same for Django 3
@alihusham1560
@alihusham1560 3 жыл бұрын
I think psycopg2 updated to psycopg2-binary
@LondonAppDeveloper
@LondonAppDeveloper 3 жыл бұрын
No those are different things. The -binary one is precompiled. I understand it's better to compile it so it's optimised for the OS.
@sushichanel7299
@sushichanel7299 6 жыл бұрын
Hi , I have this eror when type: sudo docker-compose up Building web Step 1/7 : FROM python:3 ERROR: Service 'web' failed to build: Get registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on [::1]:53: read udp [::1]:56049->[::1]:53: read: connection refused Please help me on this.
@rodrigomartinez1414
@rodrigomartinez1414 4 жыл бұрын
I have problems with the repository that you uploaded, at the moment of raising docker compose, it marks the following error: --WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or` docker-compose up --build`-- and it does not allow to create the Django service, I tried to do it in playground and it also sent me an error
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Is it a warning or an error? Warnings typically do t prevent it from working, they just let the dev know something might need to be fixed or changed in the future.
@darren1107
@darren1107 5 жыл бұрын
If you're watching this video and getting errors with the docker-compose command, you need to check this thread: stackoverflow.com/questions/51959890/docker-compose-and-django-generator-syntax-error/54437379#54437379?newreg=752e0329860c42699469069618b03fea "Your Django version is not compatible with Python 3.7 So make these changes In your Dockerfile FROM python:3.6 Restart docker using sudo service docker restart then sudo docker-compose up --build or sudo docker-compose run web python manage.py migrate and sudo docker-compose up --build" Also, if you have difficulty stopping your docker containers after starting this project: stackoverflow.com/questions/28069240/unable-to-stop-or-remove-a-container-in-docker-permission-denied-is-displayed linuxize.com/post/how-to-remove-docker-images-containers-volumes-and-networks/ This worked for me, but please, do read the articles, I'm a complete noob: "sudo aa-remove-unknown sudo service docker restart sudo docker container stop $(docker container ls -aq)"
@yassinsoltani2725
@yassinsoltani2725 4 жыл бұрын
i can't find my database in pgadmin there is no server and no database everything is empty why please ?
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Unfortunately it's difficult to tell without seeing it. If the Django project runs (and migrations apply) then the data must be somewhere.
@KanikaDawar1997
@KanikaDawar1997 4 жыл бұрын
I'm getting this error - web_1 | Is the server running on host "localhost" (127.0.0.1) and accepting web_1 | TCP/IP connections on port 5432? web_1 | could not connect to server: Cannot assign requested address web_1 | Is the server running on host "localhost" (::1) and accepting web_1 | TCP/IP connections on port 5432?
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Try stopping and starting the docker containers?
@evgeniy_melnikov
@evgeniy_melnikov 7 ай бұрын
thanks a lot
@LondonAppDeveloper
@LondonAppDeveloper 6 ай бұрын
You are most welcome
@josecortes3512
@josecortes3512 4 жыл бұрын
good stuff here thanks for your sup::port !
@LondonAppDeveloper
@LondonAppDeveloper 4 жыл бұрын
Thank you too
@Lbmaniak
@Lbmaniak 5 жыл бұрын
Thx for work
@kroloskar
@kroloskar 6 жыл бұрын
docker app does not start...
@denizgms8083
@denizgms8083 5 жыл бұрын
add apache please
@carlosmardones6422
@carlosmardones6422 6 жыл бұрын
Hey London! Thanks a lot for upload this video! I have a issue... I does all of this video but when I run python manage.py migrate, this still save all information in db.sqlite3 and not in my PostgreSQL container... Someone has the same issue than can help me??
@carlostriumph331
@carlostriumph331 6 жыл бұрын
i dont know but when i make `python manage.py migrate`, this still save all information in db.sqlite3... someone can help me ? :/
@joeygras8
@joeygras8 6 жыл бұрын
Did you change your django project's settings.py to use postgres instead of the default sqlite?
@pokegaiyui
@pokegaiyui 5 жыл бұрын
Dang I thought this video was how to connect to a Host Postgres DB and not a dockerized posgres.....
@bawantharajapaksha6417
@bawantharajapaksha6417 5 жыл бұрын
psycopg2-binary
@WeirdSide
@WeirdSide 6 жыл бұрын
Would you like to hear a poem?
@jonhpilsner3694
@jonhpilsner3694 5 жыл бұрын
красавчик, чувак!
@aram69420
@aram69420 7 ай бұрын
7:20 You should definitely use psycopg-binary instead of psycopg
@LondonAppDeveloper
@LondonAppDeveloper 6 ай бұрын
psycopg-binary is not recommended for production: www.psycopg.org/docs/install.html#psycopg-vs-psycopg-binary It's fine for learning and local development though.
Prepare a Django app for Deployment using Docker
39:10
London App Developer
Рет қаралды 90 М.
Dockerizing a Django REST Framework Project
16:58
London App Developer
Рет қаралды 53 М.
When u fight over the armrest
00:41
Adam W
Рет қаралды 16 МЛН
Elza love to eat chiken🍗⚡ #dog #pets
00:17
ElzaDog
Рет қаралды 19 МЛН
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 2 МЛН
CAN YOU DO THIS ?
00:23
STORROR
Рет қаралды 47 МЛН
Django & Postgres with Docker Best Practices
11:11
Beyond Database
Рет қаралды 17 М.
Building a Django Docker Container
34:11
Very Academy
Рет қаралды 27 М.
Deploying Django with Docker Compose, Gunicorn and Nginx
15:59
Django road
Рет қаралды 98 М.
CREATING A DJANGO PROJECT with Docker
21:17
London App Developer
Рет қаралды 51 М.
What Is JWT and Why Should You Use JWT
14:53
Web Dev Simplified
Рет қаралды 1,2 МЛН
PostgreSQL with Django // how to // tutorial
12:37
B Learning Club
Рет қаралды 56 М.
When u fight over the armrest
00:41
Adam W
Рет қаралды 16 МЛН