---
title: '<h1>How to Install PostgreSQL and pgAdmin in Docker</h1> | Zomro'
description: 'In this article, we will look at how to install PostgreSQL and the pgAdmin4 panel in a Docker container using docker-compose.'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669736570_1.png'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * How to install PostgreSQL and pgAdmin in Docker 



# How to install PostgreSQL and pgAdmin in Docker

13-11-2022

In this article, we will look at how to install PostgreSQL and the pgAdmin4 panel in a Docker container using docker-compose.  


## **Let's install Docker**

But first, we need to update the OS packages.   

    
    
    apt update

We will install the necessary packages and add a new repository:  

    
    
    apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
    
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

We will update the packages with the new repository:  

    
    
    apt update

Now let's install Docker itself.  

    
    
    apt-get install docker-ce docker-ce-cli containerd.io

Let's check the version:  

    
    
    docker --version

  
![How to install PostgreSQL and pgAdmin in Docker - 1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669736570_1.png)  
Let's check the status:
    
    
    systemctl status docker

  
![How to install PostgreSQL and pgAdmin in Docker - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669736593_2.png)  
If it hasn't started, we start it:
    
    
    systemctl start docker
    

  
And add it to autostart.
    
    
    systemctl enable docker
    

  
![How to install PostgreSQL and pgAdmin in Docker - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669736594_4.png)

## **Let's install Docker-Compose**
    
    
    curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    

  
We set the execution permissions. 
    
    
    chmod +x /usr/local/bin/docker-compose
    

  
Let's check how Docker-Compose was installed:
    
    
    docker-compose --version
    

  
![How to install PostgreSQL and pgAdmin in Docker - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669740139_5.png)  
Let's create a ***.yaml** file for Docker-Compose.  
  
To keep track of what we have installed in the future, let's create a separate folder for this project in the **/home** directory and navigate to it.
    
    
    mkdir /home/postgres && cd /home/postgres

You can also use another directory**** to place this and other projects.   
  
We will use the repository to create the **docker-compose.yaml** file at the link https://hub.docker.com/_/postgres  
  
Create a file **docker-compose.yaml** or **docker-compose.yml** ,
    
    
    vim docker-compose.yaml
    

And add the following code to it:
    
    
    version: '3.8'
    services:
      db_postgres:
        image: postgres
        container_name: postgres
        restart: always
        environment:
          POSTGRES_USER: root
          POSTGRES_PASSWORD: root
          POSTGRES_DB: test_db
        ports:
          - "54320:5432"
        volumes:
          - local_pgdata:/var/lib/postgresql/data
      pgadmin4:
        container_name: pgadmin4
        image: dpage/pgadmin4
        restart: always
        environment:
          PGADMIN_DEFAULT_EMAIL: admin@a48zomro.ml
          PGADMIN_DEFAULT_PASSWORD: root
        ports:
          - "5050:80"
        volumes:
          - pgadmin-data:/var/lib/pgadmin
    volumes:
      local_pgdata:
      pgadmin-data:
    
    

  
Where:  
  
**container_name:** the name of your container;  
**POSTGRES_USER** : User for the created database;  
**POSTGRES_PASSWORD** : password for the user we are creating;  
**POSTGRES_DB** : name of the database;  
**PGADMIN_DEFAULT_EMAIL** : email/user for logging into pgadmin;  
**PGADMIN_DEFAULT_PASSWORD** : password for the pgadmin user;  
**5050:80** : port on which pgadmin works.  
  
Let's run our script (for this you need to be in the directory where our file was created. In this case, it is **/home/postgres**):
    
    
    docker-compose up -d 

Wait for the images to download and deploy.  
  
Let's check:
    
    
    docker-compose ps

  
or 
    
    
    docker ps

  
![How to install PostgreSQL and pgAdmin in Docker - 5](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669739012_8.png)  
Now to connect to the database, you can use the container's IP with port 54320, or the name of the container postgres with port 54320 (IP:54320 or postgres:54320)   
  
To view the logs, use the command: 
    
    
    docker logs -f postgres
    

  
![How to install PostgreSQL and pgAdmin in Docker - 6](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669739321_9.png)  
To configure pgadmin — open your browser and go to the address — http://YOUR_IP_SERVER:5050/. In the connection details, specify the hostname as the name of the PostgreSQL container or the email you specified in PGADMIN_DEFAULT_EMAIL and the password root  
  
![How to install PostgreSQL and pgAdmin in Docker - 7](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669813092_screenshot_2.png)Now let's connect the PostgreSQL database server to pgadmin4.  
  
![How to install PostgreSQL and pgAdmin in Docker - 8](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669813074_screenshot_1.png)  
Enter the data you specified in **docker-compose.yaml**  
  
![How to install PostgreSQL and pgAdmin in Docker - 9](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48@server-panel.net/2022/11/01/1669739974_12.png)  
Now you can create PostgreSQL databases in pgadmin4.

We also suggest considering other useful articles:

  * [Some tips for Postgres for beginners: Part 1](https://zomro.com/rus/blog/faq/448-some-postgres-tips-for-beginners-part-1)
  * [Installing PostgreSQL and pgadmin4 on the HestiaCP panel](https://zomro.com/blog/faq/326-ustanovka-postgresql-i-pgadmin4-na-panel-hestiacp)​​​​​​​
  * [Introduction to CI/CD: Analysis of Development Methodologies](https://zomro.com/blog/faq/437-znakomstvo-s-cicd-analiz-metodologii-razrabotki)​​​​​​​​​​​​​​



Similar articles:

[How to install and configure fail2ban in Ubuntu 20.04](https://zomro.com/blog/faq/365-how-to-install-and-configure-fail2ban-in-ubuntu-2004) [How to add a new user in Windows Server 2012, 2016, 2019](https://zomro.com/blog/faq/272-kak-dobavit-novogo-polzovatelja-v-windows-server-2012-2016-2019) [How to trace](https://zomro.com/blog/faq/331-kak-proizvesti-trassirovku) [How to enable two-factor authentication in your personal account](https://zomro.com/blog/faq/321-how-to-enable-two-factor-authentication-in-your-personal-account) [Installing Yii 2.0](https://zomro.com/blog/faq/208-ustanovka-yii-20)

[ Forex Server from €7.95/mon ](/server-for-forex)
