How does the host access the program in docker?

angryTom
Release: 2020-03-13 11:03:09
Original
5729 people have browsed it

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所在的主机
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!