• Shopping Cart Shopping Cart
    0Shopping Cart
London App Developer
  • Courses
  • Consulting
  • Tutorials
  • About
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
Docker, PGAdmin, Postgres

How to use PGAdmin with a Dockerized Postgres Database

In this guide, I’ll explain how you can use PGAdmin to connect to a PostgreSQL database running in Docker.

This tutorial uses an example project setup with Django. However, it would be applicable to any service that uses PostgreSQL running with Docker Compose.

Prerequisites

You’ll need the following:

  1. The example code (a Dockerized Django and React Project)
  2. Docker Desktop
  3. PGAdmin downloaded and installed

Run Existing Project

Start by cloning the existing project to your local machine:

git clone https://github.com/LondonAppDeveloper/yt-db-django-pg-docker.git

This project contains the following components, all configured to run using Docker / Compose.

  • Django
  • React (Frontend)
  • PostgreSQL Database

Test the project by running the following:

docker compose up

Then, navigate to http://127.0.0.1:8000/admin to view the admin login.

You can create an account to login by running the following:

docker compose run --rm app sh -c "python manage.py createsuperuser"

(then follow the in-terminal steps)

Port Forwarding

The PostgreSQL server we need to connect to is running inside Docker.

Because of this, we need to ensure port forwarding is setup so we can access it via our local network.

This is already done for this project with the following block under out db service in docker-compose.yml:

    ports:
      - 5432:5432

Important: On a live machine, you should generally not allow port 5432 to be accessible by the public internet, as this makes your database vulnerable to attackers. Instead, use an SSH tunnel or at least configure your firewall to limit access to your specific IP address.

Register Server in PGAdmin

Load up PGAdmin which you should already have installed (if not, download it here).

Once loaded, right click Servers (top left) and select Register > Server.

In the General tab, give your server a name (e.g. local-dev-database)

Then, select the Connection tab and configure the following:

  • Host name/address: 127.0.0.1 – this would be the IP or hostname of the server running PostgreSQL if you are connecting to a remote server
  • Port: 5432
  • Username: user – this is the username configured here
  • Password: localdbpw – this matches the password configured here
  • Save password? – Select this to avoid entering the password every time you connect, however don’t set it on a shared machine

Once done, click Save.

You should be connected to the database right away…

On the “Dashboard” you can see some basic stats about sessions, transactions, etc.

On the left, you can expand the tree view to see a list of tables in your database schema.

Using PGAdmin

PGAdmin is an advanced tool.

We could build an entire course on how to use some of the features.

However, it’s also easy to use for basic things like running simple queries.

Listing Rows in a Table

You can view the contents of a table by right clicking it in the “tables” view and selecting View/Edit Data > All Rows.

This will return all rows in the selected table:

You can make changes and commit them directly to the database using this button:

Note: Be careful when making changes directly, as it will skip any validation checks configured in your Django models.

Running Custom Queries

You can run custom queries on your database by right clicking a table, and selecting Query Tool.

Enter a query, and hit the Run button to execute it.

Summary

That’s how you connect PGAdmin with Django.

This tool is often used for advanced database administration. For example, if you want to run custom queries or reports without writing custom Python code.

I hope you found this useful!

Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://i0.wp.com/londonappdeveloper.com/wp-content/uploads/2024/12/Blog-thumbnail-2.png?fit=1065%2C858&ssl=1 858 1065 mark https://londonappdeveloper.com/wp-content/uploads/2018/12/lon_website_logo-300x110.png mark2025-01-17 10:31:222025-01-17 11:16:57How to use PGAdmin with a Dockerized Postgres Database
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Pages

  • About
  • Consulting
  • Home
  • Tutorials

Categories

  • AI
  • Android
  • Android Studio
  • Angular
  • Aptana Studio
  • AWS
  • Bootstrap
  • Career advice
  • Celery
  • Databases
  • Deployment
  • DevOps
  • Django
  • Django REST Framework
  • Docker
  • Eclipse
  • Getting Help
  • Git
  • Git Bash
  • Git Flow
  • GitHub Actions
  • Google App Engine
  • IDE
  • Ionic Framework
  • iOS
  • JavaScript
  • Job Search
  • Links
  • Linux
  • Mac OS X
  • macOS
  • Node.JS
  • OpenAI
  • PGAdmin
  • Postgres
  • Productivity
  • Python
  • React
  • Salt Stack
  • Stack Overflow
  • Tools
  • Travis-CI
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Vagrant
  • VSCode
  • WebSockets
  • Windows 10
  • WordPress

London App Developer Ltd,

71-75 Shelton Street, Covent Garden, London, United Kingdom, WC2H 9JQ

Company registration number: 09718346

© London App Developer - London App Developer Ltd, Company Registration Number: 09718346, VAT: GB224061842
  • Link to X
  • Link to Youtube
  • Link to Facebook
  • Link to Reddit
Link to: Add Postgres Database to Dockerized Django Project Link to: Add Postgres Database to Dockerized Django Project Add Postgres Database to Dockerized Django Project Link to: How to add Async Tasks to Django with Celery Link to: How to add Async Tasks to Django with Celery How to add Async Tasks to Django with Celery
Scroll to top Scroll to top Scroll to top

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.

OKLearn more

Cookie and Privacy Settings



How we use cookies

We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

Essential Website Cookies

These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

Google Analytics Cookies

These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.

If you do not want that we track your visit to our site you can disable tracking in your browser here:

Other external services

We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

Google Webfont Settings:

Google Map Settings:

Google reCaptcha Settings:

Vimeo and Youtube video embeds:

Other cookies

The following cookies are also needed - You can choose if you want to allow them:

Privacy Policy

You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

Privacy Policy
Accept settingsHide notification only