Web API端点适用于docker-compose.yml,但不适用于仅使用Dockerfile进行构建和运行的情况

时间:2019-04-29 09:20:01

标签: docker asp.net-core docker-compose dockerfile docker-swarm

Web API端点可与docker-compose.yml一起使用,但是当我仅使用Dockerfile进行构建和运行时无法使用。

如果我使用docker-compose up,则可以使用yml中给定的端口,但是当我使用dockerfile执行yfile时,yml文件中使用的dockerfile不起作用

Docker build -t imgtag1 .
Docker run --rm -it -p 4500:80 imgtag1

(它表示应用程序已启动,但我无法点击http://localhost:4500/api/status

我正在为工作容器和不工作容器附加Docker Inspect文件。 有一些细微的差异,但我认为这些都不是造成问题的原因。 请帮助

woking
[
    {
        "Id": "d4d129f4a0af456930d2ad39fb245d9fc702b73e9bff015c25f566355d17ad9a",
        "Created": "2019-04-29T07:40:16.230861Z",
        "Path": "dotnet",
        "Args": [
            "PatientDataServices.Deployment.dll"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 23058,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2019-04-29T07:40:17.4908195Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:75a946af9bf870a89f7747ef56c343b93845c5a70c2c8f7c48292ad6137602f6",
        "ResolvConfPath": "/var/lib/docker/containers/d4d129f4a0af456930d2ad39fb245d9fc702b73e9bff015c25f566355d17ad9a/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/d4d129f4a0af456930d2ad39fb245d9fc702b73e9bff015c25f566355d17ad9a/hostname",
        "HostsPath": "/var/lib/docker/containers/d4d129f4a0af456930d2ad39fb245d9fc702b73e9bff015c25f566355d17ad9a/hosts",
        "LogPath": "/var/lib/docker/containers/d4d129f4a0af456930d2ad39fb245d9fc702b73e9bff015c25f566355d17ad9a/d4d129f4a0af456930d2ad39fb245d9fc702b73e9bff015c25f566355d17ad9a-json.log",
        "Name": "/source_patientdataservices.deployment_1",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "source_default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "8181"
                    },
                    {
                        "HostIp": "",
                        "HostPort": "8282"
                    },
                    {
                        "HostIp": "",
                        "HostPort": ""
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [],
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "shareable",
            "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": null,
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "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/c670b930d6b936e818d831e3941e3829762f80ef6d7947d84c6f5d1e2ba0bece-init/diff:/var/lib/docker/overlay2/9c34f0e20286f35df1c6f6fed0f2d13a266a064e41f10b6dde0d9a15c70aa2d4/diff:/var/lib/docker/overlay2/7d27e4323196839415c75d510de7c961908b462efb1194ac5f332d40a4ae3142/diff:/var/lib/docker/overlay2/96fe8ca3f2b3a8a11d03cb36b3d20811ed022d35c98c44041ed4343fe30ab969/diff:/var/lib/docker/overlay2/83a252b56468ca003edb1c657506578c9d088105dd00a78e193e8b12a55f5c10/diff:/var/lib/docker/overlay2/7325ad7b191a4cd367d787b4125b29db82c17700845134106f21e3405af13dcd/diff:/var/lib/docker/overlay2/4956d2de0d68f9d3bacefcbb4c7c074a01a413d60440cd0d42e42cec06740f2a/diff:/var/lib/docker/overlay2/e02fab050df41ea58b20a3bcf72833a38d8369fb4bed32cffdc200c5d9f7677f/diff",
                "MergedDir": "/var/lib/docker/overlay2/c670b930d6b936e818d831e3941e3829762f80ef6d7947d84c6f5d1e2ba0bece/merged",
                "UpperDir": "/var/lib/docker/overlay2/c670b930d6b936e818d831e3941e3829762f80ef6d7947d84c6f5d1e2ba0bece/diff",
                "WorkDir": "/var/lib/docker/overlay2/c670b930d6b936e818d831e3941e3829762f80ef6d7947d84c6f5d1e2ba0bece/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "d4d129f4a0af",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "ASPNETCORE_ENVIRONMENT=Development",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DOTNET_RUNNING_IN_CONTAINER=true",
                "DOTNET_VERSION=2.0.9",
                "DOTNET_DOWNLOAD_URL=https://dotnetcli.blob.core.windows.net/dotnet/Runtime/2.0.9/dotnet-runtime-2.0.9-linux-x64.tar.gz",
                "DOTNET_DOWNLOAD_SHA=2b49b24ef712fbfc056e0fda95ff18037b4ec938ca8bb41f4c336b6a50870e922f5093684ac92c4bb8e1155b03c36d132d7f90817793f31c9ade5267fff6629a",
                "ASPNETCORE_URLS=http://+:80",
                "ASPNETCORE_PKG_VERSION=2.0.9"
            ],
            "Cmd": null,
            "ArgsEscaped": true,
            "Image": "patientdataservicesdeployment",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": [
                "dotnet",
                "PatientDataServices.Deployment.dll"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "f11c9502d06e59a0a378c83b980b1a2b391be6b559aae00f8544919d467e2b87",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "source",
                "com.docker.compose.service": "patientdataservices.deployment",
                "com.docker.compose.version": "1.23.2"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "86def2c3042ee6c8b1afafbf489f1eb1422fb1899a2add00df8129974da811a9",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "32769"
                    },
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "8282"
                    },
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "8181"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/86def2c3042e",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "source_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "patientdataservices.deployment",
                        "d4d129f4a0af"
                    ],
                    "NetworkID": "7dbfa22d877d5e4dd393df78ca1d54ecd235f562ec828614028e9b9a0058d9a6",
                    "EndpointID": "dce413cfa2b6d804fbf34877dd385f56716f02d1407eaf99f40b71cb13af958f",
                    "Gateway": "172.20.0.1",
                    "IPAddress": "172.20.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:14:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

///////////////////////////////Below is non working////////////////////////////////////////

not working
[
    {
        "Id": "b277a02d5256ae4ad154c8d775b6b119706b531b8ca468f80209b85c22ab5b70",
        "Created": "2019-04-29T07:35:18.7950584Z",
        "Path": "dotnet",
        "Args": [
            "PatientDataServices.Deployment.dll"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 19258,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2019-04-29T07:35:19.7886605Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:75a946af9bf870a89f7747ef56c343b93845c5a70c2c8f7c48292ad6137602f6",
        "ResolvConfPath": "/var/lib/docker/containers/b277a02d5256ae4ad154c8d775b6b119706b531b8ca468f80209b85c22ab5b70/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/b277a02d5256ae4ad154c8d775b6b119706b531b8ca468f80209b85c22ab5b70/hostname",
        "HostsPath": "/var/lib/docker/containers/b277a02d5256ae4ad154c8d775b6b119706b531b8ca468f80209b85c22ab5b70/hosts",
        "LogPath": "/var/lib/docker/containers/b277a02d5256ae4ad154c8d775b6b119706b531b8ca468f80209b85c22ab5b70/b277a02d5256ae4ad154c8d775b6b119706b531b8ca468f80209b85c22ab5b70-json.log",
        "Name": "/focused_hellman",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "4500"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": true,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "shareable",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                63,
                190
            ],
            "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,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "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/66554d424fe6feb107a213091b566c2a3a49be236f02cb2e587a9d7a6129159f-init/diff:/var/lib/docker/overlay2/9c34f0e20286f35df1c6f6fed0f2d13a266a064e41f10b6dde0d9a15c70aa2d4/diff:/var/lib/docker/overlay2/7d27e4323196839415c75d510de7c961908b462efb1194ac5f332d40a4ae3142/diff:/var/lib/docker/overlay2/96fe8ca3f2b3a8a11d03cb36b3d20811ed022d35c98c44041ed4343fe30ab969/diff:/var/lib/docker/overlay2/83a252b56468ca003edb1c657506578c9d088105dd00a78e193e8b12a55f5c10/diff:/var/lib/docker/overlay2/7325ad7b191a4cd367d787b4125b29db82c17700845134106f21e3405af13dcd/diff:/var/lib/docker/overlay2/4956d2de0d68f9d3bacefcbb4c7c074a01a413d60440cd0d42e42cec06740f2a/diff:/var/lib/docker/overlay2/e02fab050df41ea58b20a3bcf72833a38d8369fb4bed32cffdc200c5d9f7677f/diff",
                "MergedDir": "/var/lib/docker/overlay2/66554d424fe6feb107a213091b566c2a3a49be236f02cb2e587a9d7a6129159f/merged",
                "UpperDir": "/var/lib/docker/overlay2/66554d424fe6feb107a213091b566c2a3a49be236f02cb2e587a9d7a6129159f/diff",
                "WorkDir": "/var/lib/docker/overlay2/66554d424fe6feb107a213091b566c2a3a49be236f02cb2e587a9d7a6129159f/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "b277a02d5256",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DOTNET_RUNNING_IN_CONTAINER=true",
                "DOTNET_VERSION=2.0.9",
                "DOTNET_DOWNLOAD_URL=https://dotnetcli.blob.core.windows.net/dotnet/Runtime/2.0.9/dotnet-runtime-2.0.9-linux-x64.tar.gz",
                "DOTNET_DOWNLOAD_SHA=2b49b24ef712fbfc056e0fda95ff18037b4ec938ca8bb41f4c336b6a50870e922f5093684ac92c4bb8e1155b03c36d132d7f90817793f31c9ade5267fff6629a",
                "ASPNETCORE_URLS=http://+:80",
                "ASPNETCORE_PKG_VERSION=2.0.9"
            ],
            "Cmd": null,
            "ArgsEscaped": true,
            "Image": "mon29_1",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": [
                "dotnet",
                "PatientDataServices.Deployment.dll"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "9982d3ce12ba7d49b0da657df85b364af07802f2839e1bfc42ee85aab6b33a49",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "4500"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/9982d3ce12ba",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "ffa80939f5103b97d049d2a9a52e988774f054e315001ed0714fd2d774bbeb1a",
            "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": "86216ae540ded3ce052979b2c254816252be71cc2af0eabb110c44edd68227d7",
                    "EndpointID": "ffa80939f5103b97d049d2a9a52e988774f054e315001ed0714fd2d774bbeb1a",
                    "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
                }
            }
        }
    }
]
  

Docker-compose配置

services:
  patientdataservices.deployment:
    build:
      context: D:\Vatan\SiemensTFS\CloudServices\Patient\Feat\Patient_Dev\PatientDataServices\Source
      dockerfile: Dockerfile
    environment:
      ASPNETCORE_ENVIRONMENT: Development
    image: patientdataservicesdeployment
    ports:
    - published: 8181
      target: 80
    - published: 8282
      target: 80
    - target: 80
version: '3.4'

1 个答案:

答案 0 :(得分:0)

环境变量ASPNETCORE_ENVIRONMENT也应该添加到docker run命令中:

docker run -e ASPNETCORE_ENVIRONMENT=Development --rm -it -p 4500:80 imgtag1