If you need a quick setup for postgres and pgadmin4 here it is what you need:
docker-compose.yml
file with the following content:version: "3"
services:
postgres_svc:
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: changeme
PGDATA: /data/postgres
ports:
- "5432:5432"
networks:
- postgres
volumes:
- ./data:/data
restart: unless-stopped
pgadmin_svc:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: admin@example.com
PGADMIN_DEFAULT_PASSWORD: admin
links:
- postgres_srv:postgres_srv
volumes:
- ./data:/data
ports:
- "5050:80"
networks:
- postgres
restart: unless-stopped
networks:
postgres:
driver: bridge
The above code will instruct docker to create a ./data
directory where it will store the database. This way, if you delete the containers you will not lose the databases.
docker-compose up
Once it finish, open the url http://localhost:5050 in your browser.
To login use the following credentials that are defined in docker-compose.yaml file:
After you have successfully logged in, click on Add Server button:
On the new popup, add a name to the server and then click on Connection tab
On the Connection tab, add the following data:
postgres_svc
postgres
changeme
Now you should be able to access your new postgres database