Unable to create postgres server (pgAdmin) - postgresql

I am trying to create a postgres server on my local. But I am getting this error:
This is my first time using postgresql so kindly let me know what I am doing wrong here.
I watched some tutorials and tried following the steps in them. Please refer to the snapshot for details of the error.

The screenshot you provided is actually the postgres client (pgadmin).
You need to have the server installed and started on port 5432. Only then you will be able to connect the client on localhost:5432
Here is the installation/download link: https://www.postgresql.org/download/
Also, you can use docker to start such a database and then connect to it. https://hub.docker.com/_/postgres The command would be i.e.
docker run --name postgres -p 5432:5432 -d postgres
Keep in mind that all data will disappear with docker once you delete the container. However, you can use volumes to persist them and reuse during your development.

Related

How to expose locally dockerized postgres service to the net

Context:
I'm building a full stack project and have decided to deploy my services on docker, I have 3 services at the moment, database-service, frontend-service, and backend-service, in addition to postgres and pgadmin.
I have set up a docker-compose file and have ran all the services.
But, at some point, I have added Prisma to my database-service and some Prisma-Docker-Apple Silicon problems have started to prevent me from build and running my database-service in the localhost.
What I decided is to build my docker image for database-service on the cloud, at fly.io.
The Issue:
As I said before, I have decided to work with Prisma on my database-service, so in my prisma.yml, I should provide my postgres link. I have tried to expose my 5432 port to the internet using ngrok, but it didn't work.
If you have encountered a similar issue, please let me know how you could resolve this conflict. thank you!
You should use ngrok tcp 5432, and not ngrok http 5432.
I've started a PosgreSQL using docker run --name so75297011 -e POSTGRES_PASSWORD=so75297011 -d -p 5432:5432 postgres:latest. Don't forget about the ports when running PostgreSQL in Docker!
And exposed it via ngrok: ngrok tcp 5432. Got a tunnel: tcp://0.tcp.eu.ngrok.io:10821 -> localhost:5432.
Here is the result, connection successful 👇

How can i see PostgreSQL UI in pgAdmin if the db is in Docker?

I have installed one open-source project from docker and that project has a database in PostgreSQL. Now I want to see the database from pgAdmin 4 and when I am trying to connect with "host.docker.internal" I am getting an error see image below.
Simply do mapping port for your PostgreSQL (which is running inside Docker). and from your pgAdmin4 you'll connect using localhost:<mapped_port>
If you're using docker-compose
services:
postgre:
ports:
- "8080:5432"
If you're using docker-cli
docker run postgre -p 8080:5432
Then from pgAdmin4 connect to your database using localhost:8080
I suspect this is a networking issue.
If port mapping does not work as suggested in other answers, try specifying the network as host for your container
If you are using docker run
--net=host
Or use the following on docker compose
network_mode: 'host'

Docker: Unable to connect to a remote Postgres server from a Docker Container

I installed the Metabase application, created a Docker container (on one Linux host) and I want to connect to a remote Postgres database (on a second Linux host) from the Docker container. The setup of Metabase allows entry of connection parameters to the Postgres database. Each time I enter the proper connection parameters in Metabase I get a database connection error. I can connect to the Postgres database from the host running the container using PSQL with no problem. My question is, is there something within Docker or the remote Postgres server that I must setup in order to allow a connection between a Docker container and a remote database? I realize this is normally caused by incorrect host/port information, problems with DNS, firewall blocking or other network problems. I am new to Docker and I do not know where to look or what to setup to make this work. Does anyone have suggestions about how to make this connection work? Thank you!

How to connect Mongo docker container to mongodb compass community installed on host

1. Pulled docker image
2. Started container by:
$ docker run mongo
3. Took the ip of container by:
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_name_or_id
4. Launched mongodb compass client on host and tried to connect to the ip
If map the container port to host port like this, then you can directly connect with loopback(127.0.0.1) ip or localhost. So you do not need to check for container IP every time. This IP is going to change everytime you create mongo container.
sudo docker run -d -p 27017:27017 -v ~/data:/data/db mongo
What kind of errors are you seeing when you attempt to connect? I'd start by locking down the IP like the previous answer suggests and try to take note of the specific errors being thrown. I've had authentication issues in the past, which weren't made very descriptive by Compass.
If you're still stuck, you could try the Docker Compose configuration I use:
https://github.com/alexmacarthur/local-docker-db/tree/master/mongo
After spinning up the container, you should be able to create databases with users. Ex:
use admin;
db.auth("root", "password");
use myDatabase;
db.createUser({user: "root", pwd: "password", roles:[{role: "readWrite" , db:"myDatabase"}]});
Once a DB and respective user are created, you should be able to access the DB through a string like this:
mongodb://user:password#localhost:27017/myDatabase
I don't know what kind of application you're building, but this might at least be able to help get you up & running for the time being.

How can I see the data of postgres database configured inside the docker container?

I am currently using the docker to run the Laravel project with a Postgres database. I created a separate container for PHP and Postgres. I created the docker network to communicate with both of them. Now I want to see the data inside my Postgres database via any client?
Can I do that? If yes please suggest the client and configurations required
I have already tried client images by docker but not helpful.
You can use psql inside your container. From the command-line, run a command similar to this:
docker exec -it container_name psql -U postgres database_name
Replace container_name and database_name with the names of your container and database. If you are using a different user, change out the username as well.