How can I solve the problem that the docker host cannot access the services in the container?

  docker, question

1. There is a response to accessing the service in the container in the container. There is no response to accessing the container service in the host, but the host can access the welcome interface of the container nginx service. The screenshot is as follows:

Accessing the service in the container in the container responded:

curl 172.17.0.2:8080

clipboard.png

The service in the sink host access container is not responding:

curl 172.17.0.2:8080

clipboard.png
Without direct port access, you will get the welcome interface code of nginx service:

curl 172.17.0.2

clipboard.png

2. Since the service can be accessed in the container, the service is started; The host can access the nginx welcome interface in the container, indicating that the host can access the 80-port service in the container. What is the problem?

Each mirror defines an interface that can be provided to the outside world. Nginx mirror only provides ports 80 and 443 by default. Naturally, you cannot access port 8080 in the container.

All you need to do isdocker createOr ..docker runCarried When Creating Containers--exposeParameter, the specified port can be opened.

--expose Expose a port or a range of ports