Host docker container port problems regarding access to the

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.

  1. In order to use the Host docker inspect 9f025896a9ecPrint 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;
  2. Into the container docker exec -it 9f025896a9ec /bin/bash;
  3. Nginx.conf disposed in the container, the reverse proxy address to http://172.1.0.1:8080 ;
  4. Exit container exit, restart nginx container on the host: docker restart 9f025896a9ec;
  5. 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'
  6. Heavy-duty firewall firewall-cmd --reload;

Guess you like

Origin www.cnblogs.com/lixingwu/p/11653014.html