远程运行多个码头容器,包括postgres数据库。
$docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------------------
fiware-cygnus /cygnus-entrypoint.sh Up (healthy) 0.0.0.0:5050->5050/tcp, 0.0.0.0:5080->5080/tcp
fiware-elasticsearch /docker-entrypoint.sh elas ... Up 9200/tcp, 9300/tcp
fiware-grafana /run.sh Up 0.0.0.0:53153->3000/tcp
fiware-iotagent pm2-runtime bin/lwm2mAgent ... Up (healthy) 0.0.0.0:4041->4041/tcp, 5684/tcp, 0.0.0.0:5684->5684/udp
fiware-memcached docker-entrypoint.sh memca ... Up 11211/tcp
fiware-mongo docker-entrypoint.sh --bin ... Up 0.0.0.0:27017->27017/tcp
fiware-nginx nginx -g daemon off; Up 0.0.0.0:53152->53152/tcp, 80/tcp
fiware-orion /usr/bin/contextBroker -fg ... Up (healthy) 0.0.0.0:1026->1026/tcp
fiware-postgres docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp
fiware-wirecloud /docker-entrypoint.sh Up (healthy) 8000/tcp我希望获得fiware-postgres容器的外部IP地址,这样我就可以通过pgAdmin进行连接,而不是通过postgres客户端管理db。看来,IPAddress of fiware-postgres只能在内部访问。
$docker inspect fiware-postgres | grep "IPAddress"
"SecondaryIPAddresses": null,
"IPAddress": "",
"IPAddress": "172.19.0.3",pgAdmin错误:
Unable to connect to server:
could not connect to server: Operation timed out
Is the server running on host "172.19.0.3" and accepting
TCP/IP connections on port 5432?是否有办法获得外部IP,或者至少有某种方式通过pgAdmin进行连接(请记住,码头容器运行在远程,通过ssh访问)。
编辑
远程主机可以通过ssh root@193.136.x.x:2222访问,因此无法到达postgres port 5432。
pgAdmin设置(连接选项卡):
Host: 193.136.xx.xx
Port: 5432
Maintenance database: postgres
Username: postgres
Password: passwordpgAdmin错误:
Unable to connect to server:
could not connect to server: Operation timed out
Is the server running on host "193.136.x.x" and accepting
TCP/IP connections on port 5432?postgres服务定义(在docker-compose中):
postgres:
restart: always
image: postgres:10
hostname: postgres
container_name: fiware-postgres
expose:
- "5432"
ports:
- "5432:5432"
networks:
- default
environment:
- "POSTGRES_PASSWORD=password"
- "POSTGRES_USER=postgres"
- "POSTGRES_DB=postgres"
volumes:
- ./postgres-data:/var/lib/postgresql/data
build:
context: .
shm_size: '2gb'发布于 2019-07-01 22:51:23
以下是对我有效的解决方案:
ssh -p 2222 root@193.136.xx.xx -L 5432:localhost:5432postgres服务器最终可通过pgAdmin访问
发布于 2019-07-01 16:37:58
假设您有将容器的端口公开给基础主机。,那么应用程序可以通过底层主机的IP地址访问。
172.19.0.3 IP地址是存在于主机上的Docker网络中的IP地址:它在外部不可用。如果您的远程主机具有IP 1.2.3.4,并且您的应用程序端口已经公开,例如,在您的撰写文件中,您有如下内容:
ports:
- "5432:5432"那么您的应用程序应该可以通过1.2.3.4:5432访问。
编辑:
如果您使用pgAdmin从本地计算机连接到远程服务器,那么就不需要ssh了:您应该发现1.2.3.4:5432仍然可以使用该服务。但是,如果您有某种形式的防火墙(例如,您正在进入AWS服务器),那么远程主机上对5432的访问很可能会被阻止。在这种情况下,考虑使用端口转发通过ssh连接将本地服务器上的连接路由到远程服务器。
ssh -L 5432:193.136.x.x:5432 193.136.x.x:2222现在使用pgAdmin连接到localhost:5432或127.0.0.1:5432。
https://stackoverflow.com/questions/56839190
复制相似问题