docker nginx container not receiving request from outside, connection refused

前端 未结 3 567
暗喜
暗喜 2020-12-06 07:29

I have a running nginx container: # docker run --name mynginx1 -P -d nginx;

And got its PORT info by docker ps: 0.0.0.0:32769->80

相关标签:
3条回答
  • 2020-12-06 08:02

    Solved.. I misunderstood how docker port mapping works. Since I'm using mac, the host for nginx container is a VM, 0.0.0.0:32769->80/tcp maps the port 80 of the container to the port 32769 of the VM.


    solution:

    1. docker-machine ip vm-name => 192.168.99.xx

    2. curl http://192.168.99.xx:32769

    0 讨论(0)
  • 2020-12-06 08:04

    Not exactly answers for your question but spend some time trying to figure out similar thing in context of "why is my docker container not connecting to elastic search localhost:9200" and this was the first S.O. question that pops up, so I hope it helps some other googling person

    if you are linking containers together (e.g. docker run --rm --name web2 --link db:db training/webapp env)

    ... then Dockers adds enviroment variables:

    DB_NAME=/web2/db DB_PORT=tcp://172.17.0.5:5432 DB_PORT_5432_TCP=tcp://172.17.0.5:5432 DB_PORT_5432_TCP_PROTO=tcp DB_PORT_5432_TCP_PORT=5432 DB_PORT_5432_TCP_ADDR=172.17.0.5

    ... and also updates your /etc/hosts

    # /etc/hosts
    #...
    172.17.0.9  db
    

    so you can technically connect to ping db

    https://docs.docker.com/v1.8/userguide/dockerlinks/

    so for elastic search is

     # /etc/hosts
     # ...
     172.17.0.28    elasticsearch f9db83d0dfb5 ecs-awseb-qa-3Pobblecom-env-f7yq6jhmpm-10-elasticsearch-fcbfe5e2b685d0984a00
    

    so wget elasticseach:9200 will work

    0 讨论(0)
  • 2020-12-06 08:15

    If you are On OSX, you are probably using a VirtualBox VM for your docker environment.

    Make sure you have forwarded your port 32769 to your actual host (the mac), in order for that port to be visible from localhost.
    This is valid for the old boot2docker, or the new docker machine.

    VBoxManage controlvm "boot2docker-vm" --natpf1 "tcp-port32769  ,tcp,,32769,,32769"
    VBoxManage controlvm "boot2docker-vm" --natpf1 "udp-port32769 ,udp,,32769,,$32769
    

    (controlvm if the VM is running, modifyvm is the VM is stopped)
    (replace "boot2docker-vm" b ythe name of your vm: see docker-machine ls)

    I would recommend to not use -P, but a static port mapping -p xxx:80 -p yyy:443.
    That way, you can do that port forwarding once, using fixed values.

    Of course, you can access the VM directly through docker-machine ip vmname

    curl http://$(docker-machine ip vmname):32769
    
    0 讨论(0)
提交回复
热议问题