卡在Windows上的docker端口转发中

时间:2019-01-30 16:08:20

标签: docker dockerfile

我正在从this site学习docker基础:我创建了一个简单的hello world Flask应用程序,我想使用docker image而不是本教程中指定的应用程序来部署/运行它。为此,我创建了一个docker映像。使用命令docker run -p 8888:5000 <name>运行此映像时,容器正确启动,但是无法在主机上访问它。

Flask应用正在侦听容器中的端口5000,我已经访问了容器tty并尝试了curl localhost:5000,它返回了正确的响应。

这是我的Dockerfile:

FROM python:3-onbuild
EXPOSE 5000
CMD ["python", "./app.py"]

这是我的目录结构:

docker
--app.py
--requirements.txt
--Dockerfile

在上述docker目录中,我运行了以下命令来创建docker映像:

docker build -t kaushal28 .

以下是docker inspect kaushal28命令的输出:

[
    {
        "Id": "sha256:37b1c19e6ab5ad7427c0d2ce192ccc2fda7d596b775eb6e4f94cda89456d19cd",
        "RepoTags": [
            "kaushal28:latest"
        ],
        "RepoDigests": [],
        "Parent": "sha256:a11e65cda9404d32ff7c1b8c6319b586e8ee890d258b8b9fd123f80e3bbe9ec7",
        "Comment": "",
        "Created": "2019-01-30T15:53:02.2468336Z",
        "Container": "5ced1f7b04db6a9dba8acd3a93b2e0c243d94be93f2a7a5eeb023a944c073520",
        "ContainerConfig": {
            "Hostname": "5ced1f7b04db",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "5000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D",
                "PYTHON_VERSION=3.6.6",
                "PYTHON_PIP_VERSION=10.0.1"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"python\" \"./app.py\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:a11e65cda9404d32ff7c1b8c6319b586e8ee890d258b8b9fd123f80e3bbe9ec7",
            "Volumes": null,
            "WorkingDir": "/usr/src/app",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "18.09.1",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "5000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "GPG_KEY=0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D",
                "PYTHON_VERSION=3.6.6",
                "PYTHON_PIP_VERSION=10.0.1"
            ],
            "Cmd": [
                "python",
                "./app.py"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:a11e65cda9404d32ff7c1b8c6319b586e8ee890d258b8b9fd123f80e3bbe9ec7",
            "Volumes": null,
            "WorkingDir": "/usr/src/app",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 700089464,
        "VirtualSize": 700089464,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/mnt/sda1/var/lib/docker/overlay2/811c6b7b8af86a24f96304703d196e7d76e3870b74e0a3f46e9e6dc9d3a1036d/diff:/mnt/sda1/var/lib/docker/overlay2/d04b14fade5b7119538f0fd491965786b358d2e7d275dfa1d16a3820984186f0/diff:/mnt/sda1/var/lib/docker/overlay2/027e8d09e71acf93c79e00733ed484f32ccf7105f7f98d555c63c38c346960c5/diff:/mnt/sda1/var/lib/docker/overlay2/bdadf210b881d7a974371247e89a4811a54e100fdb172d54e7906842dd6ff0e5/diff:/mnt/sda1/var/lib/docker/overlay2/72069dcfcd2e2130447bef86946ae71b0aba4a36d1c406387df3d616254dd29f/diff:/mnt/sda1/var/lib/docker/overlay2/8cb6a3425283dbc47fe6329f3239b694d03f8e667f96d88f2b4d41ad8f7b7813/diff:/mnt/sda1/var/lib/docker/overlay2/2bc1752de656e6ce8642391045bfb31d9a66c898b5f829866e49e7630c22829f/diff:/mnt/sda1/var/lib/docker/overlay2/e67cc2a34216b670f27ad4c407c61e40a70a3eb26fe3d9935bbafe8b11159d1d/diff:/mnt/sda1/var/lib/docker/overlay2/dfc50a5eb2b04d27a197669454cee0d3509f5fc203bc9d781f51f61ee4d53759/diff:/mnt/sda1/var/lib/docker/overlay2/8f1bc8f6064551bd23e973118651e3d015f63e7ba6900ae3e4a6e2934ce32068/diff:/mnt/sda1/var/lib/docker/overlay2/cf020baa94da1b473ca7801bcdf869414c59c82bc6ee3b1a5fe72196742d7088/diff",
                "MergedDir": "/mnt/sda1/var/lib/docker/overlay2/9e05a3b0d9f97bfb198646967b743465ee7a288ec02179ef8d46543307e08434/merged",
                "UpperDir": "/mnt/sda1/var/lib/docker/overlay2/9e05a3b0d9f97bfb198646967b743465ee7a288ec02179ef8d46543307e08434/diff",
                "WorkDir": "/mnt/sda1/var/lib/docker/overlay2/9e05a3b0d9f97bfb198646967b743465ee7a288ec02179ef8d46543307e08434/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:1618a71a1198ec75e6bb3b664e5a6f1da9037f96d912f06448c4679cbacbb280",
                "sha256:d7ed640784f1a381558346061bdf4e782887d0070fd92bca6b584401e62af5ee",
                "sha256:fd6060e25706e91e5abd0c256fa1e4f36d3d7675cd9c2ef2fe2e82c54e881047",
                "sha256:d714f65bc280978ff4691c5833f314e571c6caf300deb245a5e29284f2ad1bfe",
                "sha256:138d1921c15b49a7d46f3a8148840e91e6f7ec5fd45558c7d4d64dfe0f3659bb",
                "sha256:09e3fd9cf3572a1cb6cd07935de99830867ef42edb98cedcd9aae26cf5006b06",
                "sha256:1dc1b82fa010f46e6d5f5179dcec6fc60985ad13d2144001a2ec72fd22bfc02a",
                "sha256:fc88d2431f4dd6f19dc2ee498ca9081a62bbf8fcadf6e47d242c1c230c07f8c7",
                "sha256:29778035860f67abd5c31321ea5f6b0d1c263385421a185c4cdf800c41ae9b81",
                "sha256:0675eb6edf4e7ba22f10fd6044dfbc89a14783d5a966292b53cbc30c456798a2",
                "sha256:58873de8e78f19e1ad2559a67f664d46e0b42fd9b520d4ba2deba8458201b727",
                "sha256:e3f5c17f7cc9d38f02da7a68885bed45d758868a5c18cecbebf34d71f860cea7"
            ]
        },
        "Metadata": {
            "LastTagTime": "2019-01-30T15:53:02.286064219Z"
        }
    }
]

我正在使用docker工具箱,并使用命令docker-machine ip default给定的IP地址访问我的应用程序(即:192.168.99.100:8888)。我在这里想念什么?

0 个答案:

没有答案