Setting up PostgreSQL database with a Django Docker application

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ม.ค. 2018
  • 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...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 101

  • @saitaro
    @saitaro 5 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

    I just wanted to start learning Docker ... thanks, for this great intro!

  • @aV5d9nlUBQ9
    @aV5d9nlUBQ9 2 หลายเดือนก่อน

    Exactly what I needed. Thanks!

  • @Zzzzzzzzzzzzzzzzzzzzr
    @Zzzzzzzzzzzzzzzzzzzzr 6 ปีที่แล้ว +4

    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 ปีที่แล้ว +4

    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!

  • @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 ปีที่แล้ว +2

    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.

  • @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 ปีที่แล้ว +2

    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 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

    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

  • @giorgiberia
    @giorgiberia 5 ปีที่แล้ว +3

    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 ปีที่แล้ว +1

      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 !

  • @gabrieldjebbar5473
    @gabrieldjebbar5473 4 ปีที่แล้ว +2

    You need to update in the requirements.txt Django==1.11.17 (or more), otherwise there is failure when building.

  • @alkanecker9250
    @alkanecker9250 6 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

    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 ปีที่แล้ว +2

      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 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      @@36plain54 thank you

  • @kanakorn.h
    @kanakorn.h 4 ปีที่แล้ว +6

    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?

  • @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 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

    Would you like to hear a poem?