Docker port forwarding not working

前端 未结 5 595
故里飘歌
故里飘歌 2020-12-14 17:17

I have setup Docker container for access my machine docker container to another machine in local.

Create a container below command:

    docker run -i         


        
相关标签:
5条回答
  • 2020-12-14 17:42

    This was happening for me w/ Docker for Mac. Clicking the Docker icon, then Restart did the trick.

    0 讨论(0)
  • 2020-12-14 17:47

    When i encountered this problem (with a docker-compose managed set of docker instances), I found that deleting the network that docker-compose fixed the problem:

    docker-compose stop
    # find the network related to my docker-compose setup
    docker network ls
    docker network rm NETWORKNAME
    # let docker-compose recreate the network:
    docker-compose up -d
    
    0 讨论(0)
  • 2020-12-14 18:01

    Partial Answer:

    Now I solved this problem partially, While i try without bash in create a container and change my port to 3000(-p 3000:80) it worked for me.

    Before Command:

         docker run -it -d --name containerName -h www.myhost.net -v /var/www/html -p 3000:80 --net mynetwork --ip 172.11.0.10 --privileged myimagename  bash
    

    After Command:

        docker run -it -d --name containerName -h www.myhost.net -v /var/www/html -p 3000:80 --net mynetwork --ip 172.11.0.10 --privileged myimagename
    

    Then,

    execute the container with bin/bash

      docker exec -it containerName bin/bash
    

    Now , works locally Connected Another machine.

     hostmachineip:3000 
    
    
    I don't know docker have any port restrictions.But This solution works for me.
    
    0 讨论(0)
  • 2020-12-14 18:02

    A very common problem can be this:

    Bind your app inside Docker to 0.0.0.0, not to 127.0.0.1 address to let Docker reach the app inside container.

    0 讨论(0)
  • 2020-12-14 18:07

    Port 7000 on the host is redirecting to port 8000 in the container, but is anything listening on that port in the container?

    Your docker run command is a bit odd: -it is for running a container interactively with a terminal attached; -d is for running detached, in the background; bash at the end overrides whatever the image configures as the startup command, which is why I think there's nothing listening on port 8000.

    Try running the simplest NGINX container with this:

    docker run -d -p 8081:80 nginx:alpine
    

    And then verify you can get to the homepage:

    curl http://localhost:8081
    

    If that's working then I'd look at how you're running your image.

    0 讨论(0)
提交回复
热议问题