docker-machine: Can't access container's web server from host

后端 未结 6 1423
醉酒成梦
醉酒成梦 2020-12-23 09:39

I just installed Docker with Docker-Toolbox on my Mac using homebrew: install docker with homebrew

After creating and configuring a Container with Rails, Postgres an

相关标签:
6条回答
  • 2020-12-23 10:17

    You can find a right address to call your page this way First, find the CONTAINER ID by:

    $ docker ps
    

    You will get the information like this:

    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                          NAMES
    56dd4d582b08        abc01               "python app.py"     10 minutes ago      Up 11 minutes       80/tcp, 0.0.0.0:80->4000/tcp   flamboyant_bell
    

    Now you know the port: 4000 (scroll right this row). So that the address should be like this:

    http://192.168.99.100:4000/
    

    However, you can double check:

    $ docker port 56dd4d582b08
    

    You will get in this case the following info:

    4000/tcp -> 0.0.0.0:80
    

    Now you can try to look you project at

    http://192.168.99.100:4000/
    
    0 讨论(0)
  • 2020-12-23 10:20

    For those who tried localhost:4000 as the tutorial said but failed:

    Input this:

    $ docker-machine env
    

    and you will see something like:

    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://192.168.99.100:2376"
    export DOCKER_CERT_PATH="/Users/choi/.docker/machine/machines/dummy"
    export DOCKER_MACHINE_NAME="dummy"
    

    So you get the IP: 192.168.99.100. Then just visit 192.168.99.100:4000, as ip:your_port.

    0 讨论(0)
  • 2020-12-23 10:21

    While this solution does seem to work, it doesn't make much sense to me why it works this way. The ip address from the environment is not even on my network (and doesn't match with my ip v4 static ip address or the localhost loopback address 127.0.0.1);

    $ docker-machine env
    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://192.168.99.100:2376" 
    

    The standard (apache, jetty, tomcat, etc) is to forward to localhost (127.0.0.1), why doesn't docker do this as well?

    0 讨论(0)
  • 2020-12-23 10:23

    You need to add sonething like below "ports" entry to map port from localhost to the container:

    ports:
      - "4001:8001"
    
    0 讨论(0)
  • 2020-12-23 10:29

    192.168.99.100 is the IP of your Docker host, in this instance. You need to expose the port of your container and then you will be able to connect to it from the outside world.

    I'm not familiar with Docker Compose, but the log you have posted suggests port 8000 is exposed. Try, therefore, http://192.168.99.100:8000.

    (The reason http://192.168.99.100:2376 doesn't work is because that's the address and port of the Docker daemon itself, which isn't HTTP-based. As for 0.0.0.0: This is the address which your web server is listening on inside the container and equates to all external connections therein. However, without any ports exposed, there's no way in!)

    0 讨论(0)
  • 2020-12-23 10:33

    After exposed the port, you can access the web app by the internal IP address created by docker. You can get the IP address using the container's name running the command:

    docker inspect --format '{{ .NetworkSettings.IPAddress }}' 'container name here'
    

    Let's say that you got the IP 172.17.0.2. You can run open http://172.17.0.2:8000

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