docker container needs access to the host, can not be used to access a docker container 127.0.0.1,127.0.0.1 not host;
assigned a host ip when docker container to create, use the command docker inspect 9f025896a9ec view of the container of the relevant information in the host; which "Gateway" corresponding ip address is ip address of the host, the host access services should use this address to access;
Note that, the host opened the firewall, port should visit the open, otherwise the container is inaccessible host .
For chestnut: I now nginx installed in a container, the container ID is 9f025896a9ec, then reverse proxy to host the 8080 port.
- In order to use the Host
docker inspect 9f025896a9ec
Print containers,
find "Gateway" corresponding to the corresponding container [ip host assumed here: 172.1.0.1],
find the "IPAddress" corresponding to ip [172.1.0.2] of the container; - Into the container
docker exec -it 9f025896a9ec /bin/bash
; - Nginx.conf disposed in the container, the reverse proxy address to http://172.1.0.1:8080 ;
- Exit container exit, restart nginx container on the host:
docker restart 9f025896a9ec
; - Port 8080 open to container
firewall-cmd --permanent --add-rich-rule 'rule family=ipv4 source address=172.1.0.2 port port=8080 protocol=tcp accept'
- Heavy-duty firewall
firewall-cmd --reload
;