Home > OS >  ASP dotnet core web app container running but not opening in browser. using .net 6.0
ASP dotnet core web app container running but not opening in browser. using .net 6.0

Time:03-16

ASP dotnet core web app container running but not opening in browser. using .net 6.0

i tried http://localhot container port. please let me know where i am doing mistake.

Below i am sharing my Dockerfile and docker inpect result.

#workdir consider in app folder
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
#restoring nuget package for csproj files
COPY *.csproj ./
RUN dotnet restore
#copy all project files
COPY . ./
RUN dotnet publish -c Release -o out
#creating running image
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /app
COPY --from=build-env /app/out/ .
EXPOSE 80
ENTRYPOINT ["dotnet","dotnetpracticeapp2.dll"]

Docker container inspect output 11:11 my dotnet core web .net 6.0 version Container is running but not opening in browser,here is my some details

#workdir consider in app folder
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
#restoring nuget package for csproj files
COPY *.csproj ./
RUN dotnet restore
#copy all project files
COPY . ./
RUN dotnet publish -c Release -o out
#creating running image
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /app
COPY --from=build-env /app/out/ .
EXPOSE 80
ENTRYPOINT ["dotnet","dotnetpracticeapp2.dll"]

Docker container inspect output

  {
        "Id": "9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce",
        "Created": "2022-03-11T17:24:11.7749279Z",
        "Path": "dotnet",
        "Args": [
            "dotnetpracticeapp2.dll"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 1304,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-03-12T18:00:28.6816882Z",
            "FinishedAt": "2022-03-12T17:55:41.1098514Z"
        },
        "Image": "sha256:7d342807b790f1c7a2470db3ae47a85849bd8354939c3e4659a24d1ee388799f",
        "ResolvConfPath": "/var/lib/docker/containers/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce/hostname",
        "HostsPath": "/var/lib/docker/containers/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce/hosts",
        "LogPath": "/var/lib/docker/containers/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce-json.log",
        "Name": "/dotnetapp2",
        "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": "80"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "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": [
                16,
                125
            ],
            "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/5c6af7c62a17860faa1bccd6d57b064bc9639fbdc06dc200f12c63f0743fb0b7-init/diff:/var/lib/docker/overlay2/2fgcm3ps2hi5wuzj4nmid1gj4/diff:/var/lib/docker/overlay2/7g09cyks1ftmankkfn8rytjea/diff:/var/lib/docker/overlay2/43fbef426074496a5423ec4f2423857878095a252a5091db78cfe891af95ed3d/diff:/var/lib/docker/overlay2/dbf0cc5fcf1324ccac8470143b6b87a313e4df9a9aa344a9e600c968afcafa16/diff:/var/lib/docker/overlay2/41d81ab7ea010ecb9fac87a3b63d7183228ffc286bb2063690e5f7169f212d20/diff:/var/lib/docker/overlay2/3ee4f5439a2a5103f23ade1cde12fcf6ca386e1f2affbbd9337769ef1ef0ecd4/diff:/var/lib/docker/overlay2/15bdfbb6aecdf14bbe0b554c229ef08c4bd578c0ac2c6c002c419344d198df1a/diff:/var/lib/docker/overlay2/f8e7d9c155d0f25cd0076112aa911496febe9ca4e7a9ace2bf7a09b80f0c0bd5/diff:/var/lib/docker/overlay2/e1c521705e01879f23dadea31f56fb5ad6693acc5ddacec190216556cb8ba742/diff:/var/lib/docker/overlay2/095c04af29c37be9e84dbba0d0b7aadf6c0c91fbeca2a2fa1843815b0ebf9cd0/diff",
                "MergedDir": "/var/lib/docker/overlay2/5c6af7c62a17860faa1bccd6d57b064bc9639fbdc06dc200f12c63f0743fb0b7/merged",
                "UpperDir": "/var/lib/docker/overlay2/5c6af7c62a17860faa1bccd6d57b064bc9639fbdc06dc200f12c63f0743fb0b7/diff",
                "WorkDir": "/var/lib/docker/overlay2/5c6af7c62a17860faa1bccd6d57b064bc9639fbdc06dc200f12c63f0743fb0b7/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "9fc1f41590c7",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "ASPNETCORE_URLS=",
                "DOTNET_RUNNING_IN_CONTAINER=true",
                "DOTNET_VERSION=6.0.3",
                "ASPNET_VERSION=6.0.3",
                "Logging__Console__FormatterName=",
                "DOTNET_GENERATE_ASPNET_CERTIFICATE=false",
                "DOTNET_NOLOGO=true",
                "DOTNET_SDK_VERSION=6.0.201",
                "DOTNET_USE_POLLING_FILE_WATCHER=true",
                "NUGET_XMLDOC_MODE=skip",
                "POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetSDK-Debian-11"
            ],
            "Cmd": null,
            "Image": "parshchakurkar/dotnetapp:1.21",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": [
                "dotnet",
                "dotnetpracticeapp2.dll"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "1788646d554f21bfed7a1c0be2c884f136bd7095aee00b10f36f1ce155225bc6",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/1788646d554f",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "53d78ef8e764106367138ca777d419035a03219570a0a523875cf7157a8cd299",
            "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": "464a5c9c0dcba8adc13abe8ef9c2d4756a4b1525a92bfe643b4e2ef75b609d57",
                    "EndpointID": "53d78ef8e764106367138ca777d419035a03219570a0a523875cf7157a8cd299",
                    "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
                }
            }
        }
    }

please check and update where i am doing mistake

CodePudding user response:

I presume docker command "docker run --rm -it -p 80:80 image ID"

Map port 80 on the local machine to port 80 in the container.

Please in the Internet browser key http://localhost: you build port 80 (EXPOSE 80)

if is in dockerfile add ENV ASPNETCORE_URLS=http:// :80

Please in the Internet browser key http://0.0.0.0:80/

Reference:https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-6.0

  • Related