How to access a Docker container in the local network?

时间:2017-10-23 00:29:41

标签: mysql docker containers docker-networking

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 inspect CONTAINER_ID

where I got the IP address for the MySQL databese. Since the Docker deamon connect through bridge network, my IP addess was: 172.17.0.2. By specifying this IP I can connnect to the Database from the host computer(Fedora). But, how do I connectd to the MySQL database from another machine in the same LAN?

1 个答案:

答案 0 :(得分:1)

您需要将容器端口绑定到主机端口。将-p添加到docker run命令:

docker run -p HOST_PORT:CONTAINER_PORT

即:

docker run -p 3306:3306 .......

因此可以从Fedora的LAN界面获得MySQL。