Make container accessible only from localhost

前端 未结 2 1196
粉色の甜心
粉色の甜心 2020-12-15 17:45

I have Docker engine installed on Debian Jessie and I am running there container with nginx in it. My \"run\" command looks like this:

docker run -p 1234:80          


        
相关标签:
2条回答
  • 2020-12-15 18:20

    Specify the required host IP in the port mapping

    docker run -p 127.0.0.1:1234:80 -d -v /var/www/:/usr/share/nginx/html nginx:1.9
    

    If you are doing a reverse proxy, you might want to put them all on a user defined network along with your reverse proxy, then everything is in a container and accessible on their internal network.

    docker network create net
    docker run -d --net=web -v /var/www/:/usr/share/nginx/html nginx:1.9
    docker run -d -p 80:80 --net=web haproxy
    
    0 讨论(0)
  • 2020-12-15 18:30

    Well, solution is pretty simple, you just have to specify 127.0.0.1 when mapping port:

    docker run -p 127.0.0.1:1234:80 -d -v /var/www/:/usr/share/nginx/html nginx:1.9
    
    0 讨论(0)
提交回复
热议问题