Я не могу получить доступ к приложению контейнера с моего хоста. Я ожидаю нажать http://localhost: 3001 / demo и получить простой текст, но контейнер, кажется, недоступен. Брандмауэр не активен. Это просто ExpressJS приложение, которое я создал для тестирования. Я использую Windows 10 Pro с Hyper-V.
Кроме того, простой nginx на порту 80 работает нормально. (docker run nginx -p 80:80
)
Это результат docker version
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:23:10 2020
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:29:16 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
Ниже кода и файла Docker (работает прекрасно без docker)
// index.js
const app = require('express')();
app.get('/demo', (req, res) => res.json('Demo!'));
const server = app.listen(process.env.PORT, () => {
console.log(`Listening on ${server.address().address}:${server.address().port}`);
});
// Dockerfile
FROM node:latest
WORKDIR /src
ENV PORT=3001
COPY ["express-app", "."]
EXPOSE 3001
ENTRYPOINT ["node", "index.js"]
Я создаю образ по docker build -t express -f Dockerfile .
Я запускаю контейнер по docker run express -p 3001:3001
docker ps
4840aa7e327d express "node index.js -p 30…" 59 seconds ago Up 58 seconds 3001/tcp wonderful_easley
docker logs 4840aa7e327d
Listening on :::3001
Проверка в контейнере выполняется с помощью docker inspect 4840...
Я получаю
[
{
"Id": "4840aa7e327d425d5005d602baf28e8c5f00970e281660f567f340bf7bba3264",
"Created": "2020-03-24T04:56:10.774169154Z",
"Path": "node",
"Args": [
"index.js",
"-p",
"3001:3001"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 2467,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-03-24T04:56:11.148441022Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:9fab74e6a051386c4f0820423c35b67565b1d80117a95930e7bf49be58cfac07",
"ResolvConfPath": "/var/lib/docker/containers/4840aa7e327d425d5005d602baf28e8c5f00970e281660f567f340bf7bba3264/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/4840aa7e327d425d5005d602baf28e8c5f00970e281660f567f340bf7bba3264/hostname",
"HostsPath": "/var/lib/docker/containers/4840aa7e327d425d5005d602baf28e8c5f00970e281660f567f340bf7bba3264/hosts",
"LogPath": "/var/lib/docker/containers/4840aa7e327d425d5005d602baf28e8c5f00970e281660f567f340bf7bba3264/4840aa7e327d425d5005d602baf28e8c5f00970e281660f567f340bf7bba3264-json.log",
"Name": "/wonderful_easley",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"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": [
40,
158
],
"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/673afc4ba0603064a079e0838e3d3993631fbba6e24f5b76f04f371becd78fb5-init/diff:/var/lib/docker/overlay2/169bcc523e81d71036e2795bf43b93528861b410af969517ed2f70d30f7f10d6/diff:/var/lib/docker/overlay2/c26dd28589075e2cd12a52a2738924325da791e781f2cb283451a8d6a26fe1b9/diff:/var/lib/docker/overlay2/c81288f5d63b293cd7fbd2cf566fefbbb805fe59d8c3ffb17de37ca95ba6254b/diff:/var/lib/docker/overlay2/e113b592e8a485f656fda0974319bc496a7422c9a7d593dcd09a4bb9651bc7ff/diff:/var/lib/docker/overlay2/003113bde6da11ff5455dc2c3ba4d106c36cbd0f3d1b3e82d21b5458041ef3ac/diff:/var/lib/docker/overlay2/38c50afa09595d151f3af0bf2857e93e37ac7a4142e74130b6832f3f10039b03/diff:/var/lib/docker/overlay2/172d1d4718751de9e179f7a7f05ac7b4caef6264c8f8b1b67c51b8241984ab36/diff:/var/lib/docker/overlay2/15bd99445df3d363b6061a733f69d79dba1fc01268b6fa8c8237a5efedf69479/diff:/var/lib/docker/overlay2/68c2b9f8844e997b5406a4250aee4f099394faeada3bcc0046204d3d3ac39ef5/diff:/var/lib/docker/overlay2/6f80954a2a8f4d991965a6538d9521a9ce281589b26e2f228419536a5cc199f5/diff:/var/lib/docker/overlay2/bf0c070105eab104ddd45a1cc7950f80493e394877faa77e1c9f4c52ff2a1967/diff",
"MergedDir": "/var/lib/docker/overlay2/673afc4ba0603064a079e0838e3d3993631fbba6e24f5b76f04f371becd78fb5/merged",
"UpperDir": "/var/lib/docker/overlay2/673afc4ba0603064a079e0838e3d3993631fbba6e24f5b76f04f371becd78fb5/diff",
"WorkDir": "/var/lib/docker/overlay2/673afc4ba0603064a079e0838e3d3993631fbba6e24f5b76f04f371becd78fb5/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "4840aa7e327d",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"3001/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NODE_VERSION=13.10.1",
"YARN_VERSION=1.22.0",
"PORT=3001"
],
"Cmd": [
"-p",
"3001:3001"
],
"Image": "express",
"Volumes": null,
"WorkingDir": "/src",
"Entrypoint": [
"node",
"index.js"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "bafc5bbf61d4c3aef3450caa52479afd9c6a264a89c394d1066b257bf6317768",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3001/tcp": null
},
"SandboxKey": "/var/run/docker/netns/bafc5bbf61d4",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "86223acb4e1afeb9069d3f6af2f1cbfe59997e21889f6984c60b0cda0d565167",
"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": "32ae384f0621d25edcf263636527296f63474322b9bc6b12efe6867d8efd120d",
"EndpointID": "86223acb4e1afeb9069d3f6af2f1cbfe59997e21889f6984c60b0cda0d565167",
"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
}
}
}
}
]
ОБНОВЛЕНИЕ: Информация об IP-адресе контейнера:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
link/ipip 0.0.0.0 brd 0.0.0.0
3: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN group default qlen 1000
link/tunnel6 :: brd ::
8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
Из контейнера я могу пропинговать хост-машину.