docker容器中的.Net Core 5 API项目与docker run或docker compose不兼容-无错误
我所看到的:docker容器中的.Net Core 5 API项目与docker run或docker compose不兼容-无错误,docker,asp.net-core-5.0,Docker,Asp.net Core 5.0,我所看到的: 在VS2019中,创建一个新的.net core 5 web API应用程序,关闭https(只是为了消除测试中的证书问题),称之为dockertest 不更改应用程序 在docker中从VS中运行它--一切正常 移除dockertest docker容器(不是图像) 使用docker运行创建容器-it--rm-p 7722:80 dockertest:dev--容器运行时没有错误,日志显示它正在侦听80 请尝试访问位于的应用程序http://localhost:7722
docker运行创建容器-it--rm-p 7722:80 dockertest:dev
--容器运行时没有错误,日志显示它正在侦听80
docker build-t dockertest:0.0.1-f./dockertest/Dockerfile。
docker run-it--rm-p 7722:80 dockertest:0.0.1创建容器--容器运行时没有错误,日志显示它正在侦听80
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:80
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
货柜检验:
{
"AppArmorProfile": "",
"Args": [
"dockertest3.dll"
],
"Config": {
"AttachStderr": true,
"AttachStdin": true,
"AttachStdout": true,
"Cmd": null,
"Domainname": "",
"Entrypoint": [
"dotnet",
"dockertest3.dll"
],
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ASPNETCORE_URLS=http://+:80",
"DOTNET_RUNNING_IN_CONTAINER=true",
"DOTNET_VERSION=5.0.1",
"ASPNET_VERSION=5.0.1"
],
"ExposedPorts": {
"80/tcp": {}
},
"Hostname": "b4f5b2dff113",
"Image": "dockertest3:0.0.5",
"Labels": {},
"OnBuild": null,
"OpenStdin": true,
"StdinOnce": true,
"Tty": true,
"User": "",
"Volumes": null,
"WorkingDir": "/app"
},
"Created": "2021-01-07T09:46:30.9864781Z",
"Driver": "overlay2",
"ExecIDs": null,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/127d91088bf4c1723527366c1861d31374fae1d53981e40c148172d40d9a0d3d-init/diff:/var/lib/docker/overlay2/yraxw6cr3174e5trbzalykc0s/diff:/var/lib/docker/overlay2/nzvzpe3gdywqyblx27tbfklak/diff:/var/lib/docker/overlay2/z3tx67lfy5810vtmibw4aqadk/diff:/var/lib/docker/overlay2/6a8a63e392362af66acc3482f595bca36ec76462cc3172fd51eeb4dda31af427/diff:/var/lib/docker/overlay2/9fc4fe532dedaec2ccffe78163f348904ba6e5c53d0f269567dc9ae4d78def58/diff:/var/lib/docker/overlay2/41da0638d4d740b12bdb0d2d0ad4cfd2c42163b0d23e5a22b309eefbf86b68c1/diff:/var/lib/docker/overlay2/f0df011b8efda351f96981bdfa9f9fbc405132ee250a870cc2f69570792f65ff/diff:/var/lib/docker/overlay2/b3182380e8d22083de1e0b3468529a6b806f1569cf52589275c7e338ed717685/diff",
"MergedDir": "/var/lib/docker/overlay2/127d91088bf4c1723527366c1861d31374fae1d53981e40c148172d40d9a0d3d/merged",
"UpperDir": "/var/lib/docker/overlay2/127d91088bf4c1723527366c1861d31374fae1d53981e40c148172d40d9a0d3d/diff",
"WorkDir": "/var/lib/docker/overlay2/127d91088bf4c1723527366c1861d31374fae1d53981e40c148172d40d9a0d3d/work"
},
"Name": "overlay2"
},
"HostConfig": {
"AutoRemove": true,
"Binds": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceWriteIOps": null,
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Cgroup": "",
"CgroupParent": "",
"ConsoleSize": [
11,
302
],
"ContainerIDFile": "",
"CpuCount": 0,
"CpuPercent": 0,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpuShares": 0,
"CpusetCpus": "",
"CpusetMems": "",
"DeviceCgroupRules": null,
"DeviceRequests": null,
"Devices": [],
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IOMaximumBandwidth": 0,
"IOMaximumIOps": 0,
"IpcMode": "private",
"Isolation": "",
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"Links": null,
"LogConfig": {
"Config": {},
"Type": "json-file"
},
"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"
],
"Memory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"NanoCpus": 0,
"NetworkMode": "default",
"OomKillDisable": false,
"OomScoreAdj": 0,
"PidMode": "",
"PidsLimit": null,
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "7722"
}
]
},
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
],
"ReadonlyRootfs": false,
"RestartPolicy": {
"MaximumRetryCount": 0,
"Name": "no"
},
"Runtime": "runc",
"SecurityOpt": null,
"ShmSize": 67108864,
"UTSMode": "",
"Ulimits": null,
"UsernsMode": "",
"VolumeDriver": "",
"VolumesFrom": null
},
"HostnamePath": "/var/lib/docker/containers/b4f5b2dff11316e2b310430a5ac013816bd02418f17fd1d902f9f55bddbe3b9e/hostname",
"HostsPath": "/var/lib/docker/containers/b4f5b2dff11316e2b310430a5ac013816bd02418f17fd1d902f9f55bddbe3b9e/hosts",
"Id": "b4f5b2dff11316e2b310430a5ac013816bd02418f17fd1d902f9f55bddbe3b9e",
"Image": "sha256:eeadaeaa27801822b44a4f8a9fc6e2696a7f7d41cdd75f95fde6ad6e9170bcaf",
"LogPath": "/var/lib/docker/containers/b4f5b2dff11316e2b310430a5ac013816bd02418f17fd1d902f9f55bddbe3b9e/b4f5b2dff11316e2b310430a5ac013816bd02418f17fd1d902f9f55bddbe3b9e-json.log",
"MountLabel": "",
"Mounts": [],
"Name": "/interesting_lumiere",
"NetworkSettings": {
"Bridge": "",
"EndpointID": "ff21dbc13c19bbd2792be6f4098a477c29d9f35b16c2277f84d0dfccccddd147",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"HairpinMode": false,
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:05",
"Networks": {
"bridge": {
"Aliases": null,
"DriverOpts": null,
"EndpointID": "ff21dbc13c19bbd2792be6f4098a477c29d9f35b16c2277f84d0dfccccddd147",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAMConfig": null,
"IPAddress": "172.17.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"Links": null,
"MacAddress": "02:42:ac:11:00:05",
"NetworkID": "c730b712c96204bf2d888a9371b9b4a54f056e864bcce689f6b71e80a98eb83a"
}
},
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "7722"
}
]
},
"SandboxID": "a4897ddfc05c6ff3083ca1ee4c2e61d56e151a4d10edeca8ae22838a43f0279d",
"SandboxKey": "/var/run/docker/netns/a4897ddfc05c",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null
},
"Path": "dotnet",
"Platform": "linux",
"ProcessLabel": "",
"ResolvConfPath": "/var/lib/docker/containers/b4f5b2dff11316e2b310430a5ac013816bd02418f17fd1d902f9f55bddbe3b9e/resolv.conf",
"RestartCount": 0,
"State": {
"Dead": false,
"Error": "",
"ExitCode": 0,
"FinishedAt": "0001-01-01T00:00:00Z",
"OOMKilled": false,
"Paused": false,
"Pid": 23466,
"Restarting": false,
"Running": true,
"StartedAt": "2021-01-07T09:46:31.2780767Z",
"Status": "running"
}
}
除此之外,我还有一个部分答案 这似乎与VS2109如何定制附加到调试器的容器有很大关系 如果我运行手动docker构建并添加--no cache参数,那么创建的docker容器将正常工作,这至少是朝着正确方向迈出的一步
目前,我的工作假设是,从VS内部创建容器对于生产来说是不允许的,尽管我看不出这是预期的功能。除此之外,我还有一个部分答案 这似乎与VS2109如何定制附加到调试器的容器有很大关系 如果我运行手动docker构建并添加--no cache参数,那么创建的docker容器将正常工作,这至少是朝着正确方向迈出的一步
目前,我的工作假设是,从VS中创建容器对于生产来说是不允许的,尽管我看不出这是预期的功能。我使用Visual Studio来创建Docker容器。我发现Visual Studio 2019确实存在缺陷,因此我找到的唯一解决方案是将我的应用程序作为普通的Visual Studio项目运行,并编写DockerCompose脚本,以便暂时独立于VS发布/创建图像。我将Visual Studio用于Docker容器。我发现VisualStudio2019确实存在缺陷,因此我找到的唯一解决方案是将我的应用程序作为普通的VisualStudio项目运行,并编写DockerCompose脚本,以便暂时独立于VS发布/创建图像