How can I connect to a PostgreSQL server running inside a Docker container on a GCP virtual machine? - postgresql

I have pgAdmin4 and PostgreSQL running inside Docker containers on a GCP virtual machine. I have already ingested data into PostgreSQL and I can access the tables and databases using pgcli. However, I am unable to connect to pgAdmin4. How can I connect to the pgAdmin4?

You will access pgadmin with your browser.
When you start up the pgadmin container, you should have configured a port mapping. Add a firewall rule to your VM's network configuration for this mapped port (for example, I've configured an ingress firewall rule for 15432 because I mapped 15432 to 80 in my docker config).
Example snippet from docker-compose:
ports:
- 15432:80
Assuming you have configured an external IP address, use the external IP address and the port number in your browser to access pgadmin. Like this, where XX.XX.XX.XXX is your external IP and 15432 was mapped to port 80:
http://XX.XX.XX.XXX:15432/login

Related

can't connect mongodb on host from docker container

I have a mongo on my host machine, and an ubuntu container which is also running on my machine. I want that container to connect to mongo.
I set as host url, my host ip from docker network : 172.17.0.1
and in the /etc/mongod.conf file I set the bindIp to 0.0.0.0
from the container, I can ping the host,but the mongo service is not accessible, I get that error :
Connecting to: mongodb://172.17.0.1:27017/directConnection=true&appName=mongosh+1.5.0
MongoServerSelectionError: connection timed out
More over, I can connect from host to the mongo service with that command :
mongosh mongodb://172.17.0.1:27017
Do you know why I can't access mongo service from my container ?
You can use host.docker.internal as reference to your host machine from the container. So mongo host.docker.internal:27017 should work.
From docker documentation:
I want to connect from a container to a service on the host
The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name host.docker.internal which resolves to the internal IP address used by the host. This is for development purpose and does not work in a production environment outside of Docker Desktop.
On your local machine that has Mongo service is running, you can access by Mongo client because you expose the service at 127.0.0.1:27017.
However, it is not true if standing from your unbuntu container, there is no Mongo service is running at 172.0.0.1:27017 of the ubuntu container.
Docker-compose is the right tool for you to make containers communication to each other.

To connect postgres docker with the Widlfy docker

I have running widlfy docker and the postgres docker and also nginx docker, I want to connect all the three docker internally so my widlfy can connect to postgres and nginx and I have my url running. I have added the parameter of networking in the docker-compose.yml file but still not success.
Can you suggest how can I perform this activity of interconnection.
If you can't have all the containers in the same docker-compose.yml, then use the next.
The containers have assigned an internal port and external port, internal is inside the every docker's network and the external is where you can access using the computer's IP or localhost. In this case you need use your computer's IP, If the IP is 192.168.1.20 and the externals ports for the containers are:
Widlfy: 8080
Postgresql: 5432
ngnx: 80
Then you can connect them using this information:
Widlfy: 192.168.1.20:8080
Postgresql: 192.168.1.20:5432
ngnx: 192.168.1.20:80
The computer's IP use to change in a period of time, it depends of your modem, so check that your IP be the right when you use this option.

Is it possible set ip in docker container from same net as host?

I have twenty five containers in my docker-compose.yml file.
And I have external server with database PostgreSQL that run on host (not in docker container).
All containers can send request to database.
I would like to get IP addresses of container that send request to database.
When I try get info from DB, I can see only IP of host with docker containers.
One of the ideas it is add server lan interface to custom docker bridge net. Then I will can setup my lan network IP-addresses in each container.
Unfortunately, I can't run Postgres also in docker and configure docker-swarm or kubernetes. One of customer requirement it is run Postgres locally in a separate host.

Spring Boot Docker Container can't connect to postgresql hosted on Docker host

when I use maven to build my spring boot app the application needs to have a connection to my postgresql database in the application.properties. It only can connect when I use
spring.datasource.url=jdbc:postgresql://localhost:5432/springbootdb
but when I containerize the buileded jar file, my application can't connect to my postgres database hosted outside the Container.
what is the solution for this problem?
I am still a Beginner
From the 18.03 docs:
I want to connect from a container to a service on the host
The host has a changing IP address (or none if you have no network
access). From 18.03 onwards our recommendation is to connect to the
special DNS name host.docker.internal, which resolves to the internal
IP address used by the host.
The gateway is also reachable as gateway.docker.internal.
example:
spring.datasource.url=jdbc:postgresql://host.docker.internal:5432/springbootdb
Where you hosted your PostgreSQL database?
Replace localhost with actual machine IP address (PostgreSQL database machine address)
spring.datasource.url=jdbc:postgresql:<ip_address>:5432/springbootdb

OpenShift: How to connect to postgresql from my PC

I have an openshift app, and I just installed a postgresql DB on the same cartridge.
I have the postgresql DB installed but now I want to connect to the DB from my PC so I can start creating new tables.
Using port forwarding I found my IP for the postgresql db to be
127.3.146.2:5432
under my webaccount I see my
Database: txxx
User: admixxx
Password: xxxx
Then Using RazorSQl I try to setup a new connection
keeps coming as user password incorrect.
If I try and use the local IP to connect such as the 127.0.0.1 then I can connect fine.
How can I resolve this issue, all I am trying to do is connect to this DB so that I can create new tables.
As shown below, after running the "rhc port-forward $appname" command, you would need to connect to the ip address of 127.0.0.1 and port that shows up next to it to connect to the service you want to reach, such as postgresql. In the below example, i would connect to 127.0.0.1, port 5432. If you already have something running locally on the postgresql port, it will select another port and display it in the table. But the connection will be forwarded to your openshift gear and postgresql on your gear.
Corey-Red-Hat:~ cdaley$ rhc port-forward rt2
Checking available ports ... done
Forwarding ports ...
To connect to a service running on OpenShift, use the Local address
Service Local OpenShift
---------- -------------- ---- ---------------
httpd 127.0.0.1:8080 => 127.7.74.1:8080
postgresql 127.0.0.1:5432 => 127.7.74.2:5432
Press CTRL-C to terminate port forwarding
You can refer to the OpenShift Developer Portal for more information about using the PostgreSQL cartridge here: https://developers.openshift.com/en/databases-postgresql.html