Home  >  Article  >  Operation and Maintenance  >  How does the host access the program in docker?

How does the host access the program in docker?

angryTom
angryTomOriginal
2020-03-13 11:03:095726browse

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!

Statement:
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
Previous article:NoneNext article:主机上docker之间不通怎么办