简体   繁体   English

通过主机访问虚拟机内部的docker容器

[英]Access to the docker container inside the virtual machine through the host

I have a PostgreSQL container inside vmware(which Debian is the OS).我在 vmware 中有一个 PostgreSQL 容器(其中 Debian 是操作系统)。 I want to connect to PostgreSQL through pgAdmin in my host (windows 10)我想通过主机中的 pgAdmin 连接到 PostgreSQL(Windows 10)

I tried to get the IP address of container by using inspect flag but windows could't ping that address.我尝试使用检查标志获取容器的 IP 地址,但 windows 无法 ping 该地址。

what should I do?我应该怎么办?

You need to make sure you've started the container with a published port您需要确保已使用已发布的端口启动容器

docker run -p 5432:5432 -v pgdata:/var/lib/postgresql/data -d --name db postgres

and then you can access it through the VM's IP address然后就可以通过VM的IP地址访问了

export PGHOST=10.20.30.40 # the VM's IP address
export PGPORT=5432        # the first `docker run -p` port number (5432 is the default)
psql mydb

The docker inspect IP address is useless in this configuration and many other common setups; docker inspect IP 地址在此配置和许多其他常见设置中无用; never look it up.永远不要查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM