当前位置: 首页 > 知识库问答 >
问题:

Docker网址无法访问

何涵衍
2023-03-14
> docker-angular-test@0.0.0 start /var/www
> ng serve


chunk {main} main.js, main.js.map (main) 60.6 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 12.9 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 2.66 MB [initial] [rendered]
Date: 2020-09-14T21:40:54.116Z - Hash: df8e029eb44fcf174171 - Time: 11921ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
: Compiled successfully.

现在我正试图通过http://localhost:8080/http://172.17.0.2:8080/但该网站不可用。

docker inspect 1e
[
    {
        "Id": "1e00e3ec3c92cc9a8efd1ab7997816b89760c997e4faf09b95bdef76e6c4cc11",
        "Created": "2020-09-14T21:40:17.415811484Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "npm",
            "start"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 6478,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2020-09-14T21:40:17.703383726Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:40ce906a37347c6f7af9c2a031bc8f3846707084cfe34d48cf1a671ff6e35bc7",
        "ResolvConfPath": "/var/lib/docker/containers/1e00e3ec3c92cc9a8efd1ab7997816b89760c997e4faf09b95bdef76e6c4cc11/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/1e00e3ec3c92cc9a8efd1ab7997816b89760c997e4faf09b95bdef76e6c4cc11/hostname",
        "HostsPath": "/var/lib/docker/containers/1e00e3ec3c92cc9a8efd1ab7997816b89760c997e4faf09b95bdef76e6c4cc11/hosts",
        "LogPath": "/var/lib/docker/containers/1e00e3ec3c92cc9a8efd1ab7997816b89760c997e4faf09b95bdef76e6c4cc11/1e00e3ec3c92cc9a8efd1ab7997816b89760c997e4faf09b95bdef76e6c4cc11-json.log",
        "Name": "/keen_khorana",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/host_mnt/c/Users/Nimash.Dilanka/IdeaProjects/docker-angular-test:/var/www"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "4200/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8080"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                30,
                120
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/c836e90752c23bad48f7f93943c63012b361df00e10d5308145dad40eea7bdf1-init/diff:/var/lib/docker/overlay2/e148db30a33ae341852c931c58310c46608e8441c9b1106c3a046e6aa81bdf12/diff:/var/lib/docker/overlay2/ec3c8b010ef5b599394b5e6a0a092c37fa0861575dcfb6c1cb82d2c63f4ac419/diff:/var/lib/docker/overlay2/beecfc8f12e05640b6d6ee7e70bf8a20d511ff10f429add599aa3521b08fbd54/diff:/var/lib/docker/overlay2/521706dbca8bc30c5ac06bfaf505330b217102e6a1c14c1a1ecc679413aa00b6/diff:/var/lib/docker/overlay2/60ce6880ffd1d349855dfa425b87b757fbf47f24be0635ab3c0004eccf46949c/diff:/var/lib/docker/overlay2/31a89a298b3dd2d874a9bcebc6980a91230790cab352d38ecef08a76a8e55253/diff:/var/lib/docker/overlay2/ffc40317c4677df4814b55807b8d9316dca3e32fc66b3d2b067b5079e2e5f442/diff:/var/lib/docker/overlay2/e1a5e58a7d666b96ee70da7b889df4aa6addf69786d2d47f132c770c8c4f1501/diff:/var/lib/docker/overlay2/8dc9926d462f584f050d9147e28894ddfd86bf6ef68c1c8c5102f7aa2b5a7483/diff",
                "MergedDir": "/var/lib/docker/overlay2/c836e90752c23bad48f7f93943c63012b361df00e10d5308145dad40eea7bdf1/merged",
                "UpperDir": "/var/lib/docker/overlay2/c836e90752c23bad48f7f93943c63012b361df00e10d5308145dad40eea7bdf1/diff",
                "WorkDir": "/var/lib/docker/overlay2/c836e90752c23bad48f7f93943c63012b361df00e10d5308145dad40eea7bdf1/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/host_mnt/c/Users/Nimash.Dilanka/IdeaProjects/docker-angular-test",
                "Destination": "/var/www",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "1e00e3ec3c92",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "4200/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NODE_VERSION=14.9.0",
                "YARN_VERSION=1.22.5"
            ],
            "Cmd": [
                "npm",
                "start"
            ],
            "Image": "node",
            "Volumes": null,
            "WorkingDir": "/var/www",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "66a0fdf3d4374dcc93549f263e224bac99f5c5cfc896e2fafe7139cc2a1482cd",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "4200/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "8080"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/66a0fdf3d437",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "db7a7354e82bec6cd07118f90c47cedeacbe808209c6d8108ddfc2de3c460d1b",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "75574556ca15bd5c9b7d7d7bd391d94a8354d94183c44fa3587377b7c70352e9",
                    "EndpointID": "db7a7354e82bec6cd07118f90c47cedeacbe808209c6d8108ddfc2de3c460d1b",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

共有1个答案

汪胡非
2023-03-14

由于您要在Docker的网络上进行映射,您不能只绑定到环回接口,而是绑定到主接口,因此您需要绑定到0.0.0而不是localhost127.0.0.1

这将允许“外部”连接,因为您的主机和Docker虚拟机的“本地主机”是两种不同的东西。

这应该与使用--host标志一样简单:

node npm start -- --host 0.0.0.0
 类似资料:
  • 问题内容: 我有一个具有多个IP地址的专用服务器,某些IP关联了mac地址,而其他IP(在子网中)则没有mac地址。我已经使用以下方法创建了docker macvlan网络: 我的IP:88.99.102.115,Mac:00:50:56:00:60:42。使用以下方法创建了一个容器: 这有效,我可以从外部访问该IP地址托管的Nginx。 IP没有MAC地址且网关不在子网中的情况。 子网:88.9

  • 我是docker的新手,正在尝试容器化一个简单的Spring Boot应用程序。docker文件如下所示。 谢谢!!

  • 问题内容: 我的智慧到此为止,我梳理了每个Google搜索结果,没有任何帮助。 我完全无法使Docker容器访问互联网。IP转发已启用(),ufw已关闭,我尝试添加这些标志。我在Google上找到的所有可能的解决方案都失败了。 有人知道如何提供帮助吗? 尝试按照此处的建议重设所有内容,通过告诉我即使它没有运行,也可能破坏整个事情。 问题答案: 解决。我按照以下说明进行操作:在行中注释掉

  • 问题内容: 好的,我有一个页面,在此页面上有一个iframe。我需要做的是在iframe页面上,找出主页的URL。 我进行了搜索,我知道如果我的iframe页面位于其他域上是不可能的,因为这是跨站点脚本。但是,我读过的所有内容都说,如果iframe页面与父页面位于同一域中,那么例如,它应该可以工作: …或其他类似的组合,因为似乎有多种获取相同信息的方法。 无论如何,这就是问题所在。我的iframe

  • 我有一个 docker 容器,我想给它 --network=host AND -。我需要连接到主机网络才能将主机数据狗服务器 (UDP) 和 网络用于其数据库。 尝试添加这两个网络会导致。 知道正确的处理方法吗?

  • 我使用Docker compose和以下配置部署了标准Jenkins Docker映像: 在阅读了许多SO问题后,我测试了将Root添加到使用的docker用户组中,并验证了容器中的用户是使用的Root。 当我尝试在Jenkins UI中使用Docker URL=unix:///var/run/docker.sock添加Docker访问时,我会收到错误消息org.newsclub.net.unix