container running but cannot be visited in browser

I followed http://containertutorials.com/docker-compose/flask-compose.html and have a running container.

$ docker-compose up
Starting flaskcomposedockerexample_web_1
Attaching to flaskcomposedockerexample_web_1
web_1  |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
web_1  |  * Restarting with stat
web_1  |  * Debugger is active!

$ docker logs d66ca374c99a
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 249-821-232

Going to browser or curl will not connect:

  • Docker container can reach DNS but not resolve hosts
  • Jenkins run docker image with wrong image name
  • hub.docker.io reports tags in the web interface but we cannot some of them using the API
  • Docker - how to mount folder inside running container as volume to other running container? [closed]
  • How to install pgrep/pkill on debian wheezy docker image
  • Does Docker provide any memory efficiency on top of a VM?
  • This site can’t be reached
    
    127.0.0.1 refused to connect.
    
    $ curl 127.0.0.1:5000
    curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused
    

    Why would a container with no errors not be able to be visited? Thank you

    $ netstat 
    Active Internet connections
    Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)    
    tcp4       0      0  142.25.150.89.57766    stackoverflow.co.https ESTABLISHED
    
    tcp4       0      0  142.25.150.89.56837    8.36.126.32.http       ESTABLISHED
    tcp4       0      0  localhost.56800        localhost.56800        ESTABLISHED
    tcp4       0      0  localhost.56801        localhost.56801       ESTABLISHED
    
    
    $ docker inspect d66ca374c99a
    [
        {
            "Id": "d66ca374c99afb13a2bee56fa44fd73f4c39569edcf8c50f175bf5a124a57a73",
            "Created": "2017-04-18T14:08:54.859932607Z",
            "Path": "python",
            "Args": [
                "app.py"
            ],
            "State": {
                "Status": "running",
                "Running": true,
                "Paused": false,
                "Restarting": false,
                "OOMKilled": false,
                "Dead": false,
                "Pid": 14402,
                "ExitCode": 0,
                "Error": "",
                "StartedAt": "2017-04-18T14:09:28.342011012Z",
                "FinishedAt": "0001-01-01T00:00:00Z"
            },
            "Image": "sha256:1b3ceada8dd91e8a4403e7ee001b7a4832f72120162f8788651c3301f5ccfa89",
            "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/d66ca374c99afb13a2bee56fa44fd73f4c39569edcf8c50f175bf5a124a57a73/resolv.conf",
            "HostnamePath": "/mnt/sda1/var/lib/docker/containers/d66ca374c99afb13a2bee56fa44fd73f4c39569edcf8c50f175bf5a124a57a73/hostname",
            "HostsPath": "/mnt/sda1/var/lib/docker/containers/d66ca374c99afb13a2bee56fa44fd73f4c39569edcf8c50f175bf5a124a57a73/hosts",
            "LogPath": "/mnt/sda1/var/lib/docker/containers/d66ca374c99afb13a2bee56fa44fd73f4c39569edcf8c50f175bf5a124a57a73/d66ca374c99afb13a2bee56fa44fd73f4c39569edcf8c50f175bf5a124a57a73-json.log",
            "Name": "/flaskcomposedockerexample_web_1",
            "RestartCount": 0,
            "Driver": "aufs",
            "MountLabel": "",
            "ProcessLabel": "",
            "AppArmorProfile": "",
            "ExecIDs": null,
            "HostConfig": {
                "Binds": [
                    "/Users/cchilders/flask_compose_docker_example:/code:rw"
                ],
                "ContainerIDFile": "",
                "LogConfig": {
                    "Type": "json-file",
                    "Config": {}
                },
                "NetworkMode": "default",
                "PortBindings": {
                    "5000/tcp": [
                        {
                            "HostIp": "",
                            "HostPort": "5000"
                        }
                    ]
                },
                "RestartPolicy": {
                    "Name": "",
                    "MaximumRetryCount": 0
                },
                "AutoRemove": false,
                "VolumeDriver": "",
                "VolumesFrom": [],
                "CapAdd": null,
                "CapDrop": null,
                "Dns": null,
                "DnsOptions": null,
                "DnsSearch": null,
                "ExtraHosts": null,
                "GroupAdd": null,
                "IpcMode": "",
                "Cgroup": "",
                "Links": null,
                "OomScoreAdj": 0,
                "PidMode": "",
                "Privileged": false,
                "PublishAllPorts": false,
                "ReadonlyRootfs": false,
                "SecurityOpt": null,
                "UTSMode": "",
                "UsernsMode": "",
                "ShmSize": 67108864,
                "Runtime": "runc",
                "ConsoleSize": [
                    0,
                    0
                ],
                "Isolation": "",
                "CpuShares": 0,
                "Memory": 0,
                "NanoCpus": 0,
                "CgroupParent": "",
                "BlkioWeight": 0,
                "BlkioWeightDevice": null,
                "BlkioDeviceReadBps": null,
                "BlkioDeviceWriteBps": null,
                "BlkioDeviceReadIOps": null,
                "BlkioDeviceWriteIOps": null,
                "CpuPeriod": 0,
                "CpuQuota": 0,
                "CpuRealtimePeriod": 0,
                "CpuRealtimeRuntime": 0,
                "CpusetCpus": "",
                "CpusetMems": "",
                "Devices": null,
                "DeviceCgroupRules": null,
                "DiskQuota": 0,
                "KernelMemory": 0,
                "MemoryReservation": 0,
                "MemorySwap": 0,
                "MemorySwappiness": -1,
                "OomKillDisable": false,
                "PidsLimit": 0,
                "Ulimits": null,
                "CpuCount": 0,
                "CpuPercent": 0,
                "IOMaximumIOps": 0,
                "IOMaximumBandwidth": 0
            },
            "GraphDriver": {
                "Data": null,
                "Name": "aufs"
            },
            "Mounts": [
                {
                    "Type": "bind",
                    "Source": "/Users/cchilders/flask_compose_docker_example",
                    "Destination": "/code",
                    "Mode": "rw",
                    "RW": true,
                    "Propagation": ""
                }
            ],
            "Config": {
                "Hostname": "d66ca374c99a",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "ExposedPorts": {
                    "5000/tcp": {}
                },
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ],
                "Cmd": [
                    "app.py"
                ],
                "ArgsEscaped": true,
                "Image": "flaskcomposedockerexample_web",
                "Volumes": {
                    "/code": {}
                },
                "WorkingDir": "/app",
                "Entrypoint": [
                    "python"
                ],
                "OnBuild": null,
                "Labels": {
                    "com.docker.compose.config-hash": "3c65c28cc5926f591068f82a4d028ae50573b14ac4059ebe17b196be2185995a",
                    "com.docker.compose.container-number": "1",
                    "com.docker.compose.oneoff": "False",
                    "com.docker.compose.project": "flaskcomposedockerexample",
                    "com.docker.compose.service": "web",
                    "com.docker.compose.version": "1.11.2"
                }
            },
            "NetworkSettings": {
                "Bridge": "",
                "SandboxID": "6b4cd91f76cb21f70fc7b1b17e403f21ef790cc1e02fee5547740ac5192229fe",
                "HairpinMode": false,
                "LinkLocalIPv6Address": "",
                "LinkLocalIPv6PrefixLen": 0,
                "Ports": {
                    "5000/tcp": [
                        {
                            "HostIp": "0.0.0.0",
                            "HostPort": "5000"
                        }
                    ]
                },
                "SandboxKey": "/var/run/docker/netns/6b4cd91f76cb",
                "SecondaryIPAddresses": null,
                "SecondaryIPv6Addresses": null,
                "EndpointID": "e05d8bf26815734a146d6f4b1fb803b365629dfce732a2b21993970a33e54a80",
                "Gateway": "162.16.0.1",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "IPAddress": "162.16.0.4",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "MacAddress": "02:42:bd:55:00:04",
                "Networks": {
                    "bridge": {
                        "IPAMConfig": null,
                        "Links": null,
                        "Aliases": null,
                        "NetworkID": "2fd3c33ec08105cd00de10ab5555554572bac4548866239aa375e8df60ed3aa",
                        "EndpointID": "e05d8bf26815734a146d6f4b1fb80555559dfce732a2b21993970a33e54a80",
                        "Gateway": "162.16.0.1",
                        "IPAddress": "162.16.0.4",
                        "IPPrefixLen": 16,
                        "IPv6Gateway": "",
                        "GlobalIPv6Address": "",
                        "GlobalIPv6PrefixLen": 0,
                        "MacAddress": "02:42:44:00:04"
                    }
                }
            }
        }
    ]
    
    
    
    $ netstat -tnlp
    netstat: option requires an argument -- p
    Usage:  netstat [-AaLlnW] [-f address_family | -p protocol]
        netstat [-gilns] [-f address_family]
        netstat -i | -I interface [-w wait] [-abdgRtS]
        netstat -s [-s] [-f address_family | -p protocol] [-w wait]
        netstat -i | -I interface -s [-f address_family | -p protocol]
        netstat -m [-m]
        netstat -r [-Aaln] [-f address_family]
        netstat -rs [-s]
    
    $ netstat -tnpl
    netstat: l: unknown or uninstrumented protocol
    

  • Debian Packagemanager won't install vagrant.deb package on alpine-linux, while building docker image
  • Boot2Docker starting Ubuntu image
  • Problems with database setup on cookiecutter-django
  • how to create a volume in docker with filesystem?
  • Docker-machine Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  • Docker ps -a doesn't show a stopped mysql client running container
  • One Solution collect form web for “container running but cannot be visited in browser”

    There are two problems first the tutorial you are referring to has syntax error in the first line of app.py it should be

    from flask import Flask 
    

    Secondly, docker works differently in Mac and windows docker doesn’t directly map the ports to the local Host instead of that docker creates a very small Linux virtual machine which is approximately 24 mb in size and then run containers inside that this virtual machine which is also called docker machine so instead of mapping the ports to localhost docker maps it to docker machine so your containers should be accessible to

    http://docker_machine_ip:port_no 
    

    Instead of

    http://localhost:port_no
    

    The default docker machine ip can be found using

     docker-machine ip dev
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.