Connection refused on docker container

后端 未结 6 914
面向向阳花
面向向阳花 2020-12-13 05:47

I\'m new to Docker and trying to make a demo Rails app. I made a dockerfile that looks like this:

FROM ruby:2.2
MAINTAINER marko@codeship.com

# Install apt         


        
相关标签:
6条回答
  • 2020-12-13 06:12

    Command EXPOSE in your Dockerfile lets you bind container's port to some port on the host machine but it doesn't do anything else. When running container, to bind ports specify -p option.

    So let's say you expose port 5000. After building the image when you run the container, run docker run -p 5000:5000 name. This binds container's port 5000 to your laptop/computers port 5000 and that portforwarding lets container to receive outside requests.

    This should do it.

    0 讨论(0)
  • 2020-12-13 06:16

    I had the same problem. I was using Docker Toolbox on Windows Home. Instead of localhost I had to use http://192.168.99.100:8080/.

    You can get the correct IP address using the command:

    docker-machine ip
    

    The above command returned 192.168.99.100 for me.

    0 讨论(0)
  • 2020-12-13 06:25

    You need to publish the exposed ports by using the following options:

    -P (upper case) or --publish-all that will tell Docker to use random ports from your host and map them to the exposed container's ports.

    -p (lower case) or --publish=[] that will tell Docker to use ports you manually set and map them to the exposed container's ports.

    The second option is preferred because you already know which ports are mapped. If you use the first option then you will need to call docker inspect demo and check which random ports are being used from your host at the Ports section.

    Just run the following command:

    docker run -it -p 8080:8080 demo
    

    After that your url will work.

    0 讨论(0)
  • 2020-12-13 06:25

    In Windows, you also normally need to run command line as administrator.

    As standard-user:

    docker build -t myimage -f Dockerfile .
    Sending build context to Docker daemon  106.8MB
    Step 1/1 : FROM mcr.microsoft.com/dotnet/core/runtime:3.0
    Get https://mcr.microsoft.com/v2/: dial tcp: lookup mcr.microsoft.com on [::1]:53: read udp [::1]:45540->[::1]:53: read: 
    >>>connection refused
    

    But as an administrator.

    docker build -t myimage -f Dockerfile .
    Sending build context to Docker daemon  106.8MB
    Step 1/1 : FROM mcr.microsoft.com/dotnet/core/runtime:3.0
    3.0: Pulling from dotnet/core/runtime
    68ced04f60ab: Pull complete                                                                                             e936bd534ffb: Pull complete                                                                                             caf64655bcbb: Pull complete                                                                                             d1927dbcbcab: Pull complete                                                                                             Digest: sha256:e0c67764f530a9cad29a09816614c0129af8fe3bd550eeb4e44cdaddf8f5aa40
    Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/runtime:3.0
     ---> f059cd71a22a
    Successfully built f059cd71a22a
    Successfully tagged myimage:latest
    
    0 讨论(0)
  • 2020-12-13 06:29

    If you are using Docker toolkit on window 10 home you will need to access the webpage through docker-machine ip command. It is generally 192.168.99.100:

    It is assumed that you are running with publish command like below.

    docker run -it -p 8080:8080 demo
    

    With Window 10 pro version you can access with localhost or corresponding loopback 127.0.0.1:8080 etc (Tomcat or whatever you wish). This is because you don't have a virtual box there and docker is running directly on Window Hyper V and loopback is directly accessible.

    Verify the hosts file in window for any digression. It should have 127.0.0.1 mapped to localhost

    0 讨论(0)
  • 2020-12-13 06:31

    In Docker Quickstart Terminal run following command: $ docker-machine ip 192.168.99.100

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