Php 从主机访问docker:(56)Recv故障:对等方重置连接
嗨,我创建了一个centOS容器并安装了(php、apache、composer和lumen) 当我跑步时: php-S localhost:8000-t public 输出似乎是正确的:Php 从主机访问docker:(56)Recv故障:对等方重置连接,php,apache,docker,curl,lumen,Php,Apache,Docker,Curl,Lumen,嗨,我创建了一个centOS容器并安装了(php、apache、composer和lumen) 当我跑步时: php-S localhost:8000-t public 输出似乎是正确的: php -S localhost:8000 -t public PHP 7.0.27 Development Server started at Tue Jan 23 04:33:55 2018 Listening on http://localhost:8000 Document root is /home
php -S localhost:8000 -t public
PHP 7.0.27 Development Server started at Tue Jan 23 04:33:55 2018
Listening on http://localhost:8000
Document root is /home/blog/public
Press Ctrl-C to quit
我这样运行容器,以便能够在其中运行服务器:
docker run -it -p 8899:8000 shizus/centos:blog /usr/bin/sh
但在主机上,当我
curl localhost:8899
它回来了
curl localhost:8899
curl: (56) Recv failure: Connection reset by peer
我也试过使用容器ip,端口8000也试过使用127.0.01:8899
我还尝试使用server start命令运行容器
docker run -p 8899:8000 shizus/centos:blog php -S localhost:8000 -t /home/blog/public
y也处于分离模式
docker run -d -p 8899:8000 shizus/centos:blog php -S localhost:8000 -t /home/blog/public
这是我从docker inspect
[
{
"Id": "a136be80b2ba2b43d627c376b3e8286555a473e67b10175f9be772310b331e4b",
"Created": "2018-01-23T15:54:04.812672134Z",
"Path": "php",
"Args": [
"-S",
"localhost:8000",
"-t",
"/home/blog/public"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 16953,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-01-23T15:54:05.180502274Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:ce9229626683d17176d2f8e5f99e948bec16b4627cd268250c1e03d5aa449833",
"ResolvConfPath": "/var/lib/docker/containers/a136be80b2ba2b43d627c376b3e8286555a473e67b10175f9be772310b331e4b/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/a136be80b2ba2b43d627c376b3e8286555a473e67b10175f9be772310b331e4b/hostname",
"HostsPath": "/var/lib/docker/containers/a136be80b2ba2b43d627c376b3e8286555a473e67b10175f9be772310b331e4b/hosts",
"LogPath": "/var/lib/docker/containers/a136be80b2ba2b43d627c376b3e8286555a473e67b10175f9be772310b331e4b/a136be80b2ba2b43d627c376b3e8286555a473e67b10175f9be772310b331e4b-json.log",
"Name": "/wizardly_newton",
"RestartCount": 0,
"Driver": "aufs",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"8000/tcp": [
{
"HostIp": "",
"HostPort": "8899"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"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": [],
"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": [],
"Config": {
"Hostname": "a136be80b2ba",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8000/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"php",
"-S",
"localhost:8000",
"-t",
"/home/blog/public"
],
"Image": "shizus/centos:blog",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"build-date": "20180107",
"license": "GPLv2",
"name": "CentOS Base Image",
"vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "135e35cf77438a9bcfb9b5519d3fa59e9d15bc506dee164c8c61371e97271c53",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8899"
}
]
},
"SandboxKey": "/var/run/docker/netns/135e35cf7743",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "9f6f68e3b3198981cb5c747dbfd3a0d689784749acc5bc9379d8adac73dc56f6",
"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": "0d87bf18821547b37d82e877c5503d2a139d631b05fcc10fc6f99a4cd4209db9",
"EndpointID": "9f6f68e3b3198981cb5c747dbfd3a0d689784749acc5bc9379d8adac73dc56f6",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
}
]
当我尝试
curl localhost:8899
curl: (56) Recv failure: Connection reset by peer
如果我尝试
curl 172.17.0.2:8000
curl: (7) Failed to connect to 172.17.0.2 port 8000: Connection refused
你觉得怎么样
谢谢 使用命令
php-S 127.0.0.1:8000
仅将php进程绑定到docker容器的环回接口(与主机的不同)。当您尝试从外部网络(从主机)连接时,它将无法工作。您需要绑定到所有网络接口
尝试:
php -S 0.0.0.0:8000 -t public
这样,您的php进程将监听容器内的所有网络接口,您应该能够从主机访问它是!我一读到你的答案就知道它完全有道理!非常感谢。