All the work in this article is based on WSL(Windows Subsystem for Linux).
There are two versions for dokcer compose, V1 and V2.
compose
command as part of Docker CLI, so use V2 if you don't know which one to use.You must run docker daemon to run PostgreSQL and pgAdmin using Docker.
You can locally install PostgreSQL and pgAdmin with below links.
However, there is a way of using PostgreSQL, pgAdmin without local installation, which is using a docker.
We will run uploaded PostgreSQL and pgAdmin images through a yaml file.
But before that, you must download docker-compose in order to run yaml file.
From below link, get latest release version of Docker Compose.
Docker Compose Version
In terminal, Run below code to download current stable release of Docker Compose
Currently, latest release version is 2.4.1
$ DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
$ mkdir -p $DOCKER_CONFIG/cli-plugins
$ curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
Apply executable permissions to the binary.
$ chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
Test installation by printing version
$ docker compose version
> Docker Compose version v2.4.1
docker-compose.yml
version: "3"
services:
db:
container_name: test_db
image: postgres
environment:
POSTGRES_USER : test
POSTGRES_PASSWORD : 1234
POSTGRES_DB : test_db
ports:
- "5432:5432"
pgadmin:
container_name: test_pgadmin
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL : user@test.com
PGADMIN_DEFAULT_PASSWORD: 1234
ports:
- "5050:80"
depends_on:
- db
Above is simple code which will run pgadmin and postgres.
Now run the below command where docker-compose.yml is located.
$ docker compose up
If you successfully composed above code, you will be able to access pgadmin with localhost:5050
If the website looks like below picutre, Congrautations! you have successfully run pgAdmin with docker.
However, It is not done yet since you have to connect postgres db to pgAdmin
.
Login pgAdmin with emil and password that is written in pgadmin section of yaml file which are user@test.com
and 1234
After login, Click Servers / Register / Server
In General, Name
anything you want to name the server.
In Connection, write container_name of db on Host name
and fill out username and password.
Tip : Host name / address
should be filled with IP + port number of database if you connect local installed pgAdmin and Postgres db. However, docker provides IP + port as container name if you run both program through the docker.
If you are successfully connected pgAdmin with Postgres DB, you will see the database under the server like below picture.