Home > Article > Operation and Maintenance > How does the host access the program in docker?
How does the host access the program in docker
Requirements:
1: Access the application in docker locally
2: Other machines access the application in docker
3: DockerB access the application in dockerA
Known environment:
Host IP: 192.168.220.123
Container A has been started, IP: 172.17.0.2, Tomcat has been started, and the port is 8080.
Access the application in dockerA:
curl http://localhost:8080/ #当前docker curl http://172.17.0.2:8080/ #当前docker和docker所在的主机
There are two problems here:
1: Other hosts How to access this application?
2: What should I do if the ip changes after restarting docker? (IP is automatically assigned after docker is started)
Docker provides port mapping function, add the -p parameter when starting docker, map port: container application port
docker run -d -p 58080:8080 aa79
Access the application in dockerA:
curl http://localhost:8080/ #当前docker curl http://172.17.0.2:8080/ #当前docker和docker所在的主机 curl http://192.168.220.123:58080 #其他主机/其他docker
For more tutorials, please pay attention to PHP Chinese websitedocker tutorial.
The above is the detailed content of How does the host access the program in docker?. For more information, please follow other related articles on the PHP Chinese website!