[英]How to access a Docker container in the local network?
I have pulled an MYSQL image from Docker Hub and ran it by setting necessary credentials, such as username, password etc. Then I have inspected the container by:我从 Docker Hub 中提取了一个 MYSQL 镜像,并通过设置必要的凭据(例如用户名、密码等)来运行它。然后我通过以下方式检查了容器:
docker inspect CONTAINER_ID
where I got the IP address for the MySQL databese.在那里我得到了 MySQL 数据库的 IP 地址。 Since the Docker deamon connect through bridge network, my IP addess was: 172.17.0.2.
由于 Docker 守护进程通过桥接网络连接,因此我的 IP 地址为:172.17.0.2。 By specifying this IP I can connnect to the Database from the host computer(Fedora).
通过指定这个 IP,我可以从主机(Fedora)连接到数据库。 But, how do I connectd to the MySQL database from another machine in the same LAN?
但是,如何从同一局域网中的另一台机器连接到 MySQL 数据库?
You need to bind the container port to a host machine port.您需要将容器端口绑定到主机端口。 Adding
-p
to the docker run
command:将
-p
添加到docker run
命令:
docker run -p HOST_PORT:CONTAINER_PORT
Ie: IE:
docker run -p 3306:3306 .......
So MySQL is available from the Fedora's LAN interface.因此 MySQL 可从 Fedora 的 LAN 接口使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.