Тёмный

Setting up PostgreSQL database with a Django Docker application 

London App Developer
Подписаться 20 тыс.
Просмотров 64 тыс.
50% 1

In this video, I’ll show you how to set up a PostgreSQL database with a Django Docker application. This video follows from my first video Dockerizing a Django REST Framework Project: • Dockerizing a Django R...
Docker: www.docker.com
Docker-Compose: docs.docker.com/compose/install/
GitHub Repo: github.com/LondonAppDeveloper...
The course I refer to in the video is Build Your Own Backend REST API using Django REST Framework Course: www.udemy.com/course/django-p...
OTHER COURSES
• Build a Backend REST API with Python & Django, Django REST Framework and Docker using Test Driven Development (TDD) ADVANCED: www.udemy.com/course/django-p...
• DevOps Deployment Automation with Terraform, AWS and Docker: londonappdeveloper.thinkific....
VIDEOS YOU MIGHT LIKE:
○ Prepare a Django app for Deployment using Docker - • Prepare a Django app f...
○ BUILD A BACKEND REST API with Python, Django REST Framework, Django, Vagrant & VirtualBox - • Build a BEGINNER backe...
○ BUILD A BACKEND REST API with Python, Django & Test Driven Development - • Build an ADVANCED back...
○ CREATING A DJANGO PROJECT with Docker - • CREATING A DJANGO PROJ...
○ Dockerizing a Django REST Framework Project - • Dockerizing a Django R...
○ THE 4 BEST WAYS TO DEPLOY A DJANGO APPLICATION - • The 4 best ways to dep...

Наука

Опубликовано:

 

14 янв 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 101   
@saitaro
@saitaro 5 лет назад
Super useful. That just worked with my old project. Thank you, Mark!
@peternjenga5045
@peternjenga5045 5 лет назад
Worked perfectly! Thanks mate.
@yvoncomeau
@yvoncomeau 6 лет назад
Excellent demo. Thanks!
@tsoonamik
@tsoonamik 5 лет назад
You are my superhero. Saved a lot of my time
@ma-tei
@ma-tei 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 2 месяца назад
Exactly what I needed. Thanks!
@LondonAppDeveloper
@LondonAppDeveloper 2 месяца назад
Splendid.
@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
@nitishpatkar6190
@nitishpatkar6190 6 лет назад
It helped me me a lot!
@rhonaldjr
@rhonaldjr 4 года назад
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.
@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' .
@snowpeak
@snowpeak 6 лет назад
How do you deploy this to a VPS?
@saleee_6
@saleee_6 3 года назад
Thank you brother!
@jeremiahj2314
@jeremiahj2314 5 лет назад
docker-compose up fails with'Error: Service 'web' failed to build unexpected EOF' any help would be appreciated. great vid.
@thedemonlord9232
@thedemonlord9232 4 года назад
how can you access that database? when I add network_mode: bridge it fails building
@nielsSavantKing
@nielsSavantKing 11 месяцев назад
@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
@nikitakurabtsev1222
@nikitakurabtsev1222 Год назад
Thank you.
@jeetpatel2828
@jeetpatel2828 4 года назад
can you please do it with the mysql as well
@Lbmaniak
@Lbmaniak 5 лет назад
Thx for work
@36plain54
@36plain54 3 года назад
many many thanks!
@LondonAppDeveloper
@LondonAppDeveloper 3 года назад
Most welcome!
@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??
@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?
@elenaperez6327
@elenaperez6327 3 года назад
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 3 года назад
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...).
@usamakaleem8378
@usamakaleem8378 3 года назад
Great but i was also expecting the pg_admin setup and also change user for postgres and password
@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é.
@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
@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.
@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
@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
@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.
@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
@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 3 года назад
It might be fixed using python:3.6.12 version of python in the Dockerfile.
@evgeniy_melnikov
@evgeniy_melnikov 3 месяца назад
thanks a lot
@LondonAppDeveloper
@LondonAppDeveloper 2 месяца назад
You are most welcome
@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!
@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.
@josecortes3512
@josecortes3512 3 года назад
good stuff here thanks for your sup::port !
@LondonAppDeveloper
@LondonAppDeveloper 3 года назад
Thank you too
@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
@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 3 года назад
Hi I got the same error, how did you fix it?
@minhajuddinansari561
@minhajuddinansari561 Год назад
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.
@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?
@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.
@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?
@denizgms8083
@denizgms8083 5 лет назад
add apache please
@jonhpilsner3694
@jonhpilsner3694 5 лет назад
красавчик, чувак!
@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 3 года назад
environment: - "POSTGRES_HOST_AUTH_METHOD=trust" in db service solved this for me
@WarrenBey
@WarrenBey Год назад
Amazing he was able to run a PG image without a PG password.
@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
@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.
@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 Год назад
Try this. db: image: postgres environment: POSTGRES_HOST_AUTH_METHOD: trust
@aram69420
@aram69420 4 месяца назад
@@minhajuddinansari561 Wow that helped a lot, thank you !
@kroloskar
@kroloskar 6 лет назад
docker app does not start...
@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.
@vinsmokearifka
@vinsmokearifka 4 года назад
thanks for the tutorial, but i got `django.db.utils.OperationalError: FATAL: password authentication failed for user "postgres"`
@36plain54
@36plain54 3 года назад
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 3 года назад
@@36plain54 thank you
@kanakorn.h
@kanakorn.h 4 года назад
psycopg2 ---> IMHO pronounced "psycho pg two" LOL
@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.
@gouthambolt
@gouthambolt 3 года назад
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 3 года назад
Lol thank you for taking our course. Sorry it was boring but glad to hear the boredom paid off in the end :)
@toniehubert
@toniehubert 3 года назад
Why are you in bieszczady mountains :O?
@LondonAppDeveloper
@LondonAppDeveloper 3 года назад
The photo is from Banff National Park (Canada).
@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.
@bawantharajapaksha6417
@bawantharajapaksha6417 4 года назад
psycopg2-binary
@darren1107
@darren1107 4 года назад
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)"
@pokegaiyui
@pokegaiyui 5 лет назад
Dang I thought this video was how to connect to a Host Postgres DB and not a dockerized posgres.....
@aram69420
@aram69420 4 месяца назад
7:20 You should definitely use psycopg-binary instead of psycopg
@LondonAppDeveloper
@LondonAppDeveloper 2 месяца назад
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.
@WeirdSide
@WeirdSide 5 лет назад
Would you like to hear a poem?
Далее
Prepare a Django app for Deployment using Docker
39:10
Django & Postgres with Docker Best Practices
11:11
Просмотров 16 тыс.
Dockerizing a Django REST Framework Project
16:58
Просмотров 53 тыс.
Building a Django Docker Container
34:11
Просмотров 22 тыс.
Creating Django App on Docker
26:58
Просмотров 56 тыс.
What is Apache Kafka®?
11:42
Просмотров 344 тыс.
Смартфон УЛУЧШАЕТ ЗРЕНИЕ!?
0:41