• docker--.netcore


    1. 安装docker:
    2. 安装 dotnet:   sudo yum install dotnet-sdk-5.0

    3. mkdir webapi && cd webapi && dotnet new webapi  && dotnet  build &&  dotnet  bin/Debug/net5.0/webapi.dll  &  (dotnet -h 可以查看帮助)。 

    4. wget  https://localhost:5001/WeatherForecast --no-check-certificate 查看结果

    5. 新建Dockerfile

    #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

    FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
    WORKDIR /app
    EXPOSE 80

    FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
    WORKDIR /src
    RUN ls
    COPY . .
    RUN ls -l
    RUN pwd
    RUN dotnet restore "webapi.csproj"

    RUN dotnet build "webapi.csproj" -c Release -o /app/build

    FROM build AS publish
    RUN dotnet publish "webapi.csproj" -c Release -o /app/publish

    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "webapi.dll"]

    运行 docker
    docker bulid -t webapi_example . docker run -p 80:80 -d --name ddd webapi_example wget localhost/WeatherForecast

    docker inspect:

    [root@node1 webapi]# docker inspect 40efc7830b15
    [
        {
            "Id": "40efc7830b150350d185dbf63c1667401a0d912896aa73ed7dd56f6a18e05fa1",
            "Created": "2021-10-31T09:21:05.976335337Z",
            "Path": "dotnet",
            "Args": [
                "webapi.dll"
            ],
            "State": {
                "Status": "running",
                "Running": true,
                "Paused": false,
                "Restarting": false,
                "OOMKilled": false,
                "Dead": false,
                "Pid": 11512,
                "ExitCode": 0,
                "Error": "",
                "StartedAt": "2021-10-31T09:21:06.998037393Z",
                "FinishedAt": "0001-01-01T00:00:00Z"
            },
            "Image": "sha256:3af3eb1469f7bd42e3efd50fbfadc474de212807e4274a685bb510e15e28c189",
            "ResolvConfPath": "/var/lib/docker/containers/40efc7830b150350d185dbf63c1667401a0d912896aa73ed7dd56f6a18e05fa1/resolv.conf",
            "HostnamePath": "/var/lib/docker/containers/40efc7830b150350d185dbf63c1667401a0d912896aa73ed7dd56f6a18e05fa1/hostname",
            "HostsPath": "/var/lib/docker/containers/40efc7830b150350d185dbf63c1667401a0d912896aa73ed7dd56f6a18e05fa1/hosts",
            "LogPath": "/var/lib/docker/containers/40efc7830b150350d185dbf63c1667401a0d912896aa73ed7dd56f6a18e05fa1/40efc7830b150350d185dbf63c1667401a0d912896aa73ed7dd56f6a18e05fa1-json.log",
            "Name": "/ddd",
            "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": [
                    0,
                    0
                ],
                "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/e463d26f5ef72a58945c059eb5c254617bb9d32395084b8eeec00073a67c1ea4-init/diff:/var/lib/docker/overlay2/c933127e107f6fa43e2197eaac9aa35e014a2fbf2e21966e0a5f4ef469257acb/diff:/var/lib/docker/overlay2/7606e281c1bae1853938bd94e8cdaea66456ab85f10764e88bf29a5e62360e84/diff:/var/lib/docker/overlay2/885849a72dfd973848774bebd840115e8c6c336d7ec737ef91d31abf6cf33529/diff:/var/lib/docker/overlay2/9e44ab64f75566e30620ed393caaf2da676b294ab32cd0269a35ec72b3478e11/diff:/var/lib/docker/overlay2/ecdb26ad1774f49cf394b8625d966951a574103d31199c3fef49510efcd68832/diff:/var/lib/docker/overlay2/152183a054389ae7b7432ea0c85a75e65a8839cc4ea14f3b4490c14f4ce6ab01/diff:/var/lib/docker/overlay2/49e3a5db616553f6be29cec2833991ea6722039dd67a5184327d012a6f41841c/diff",
                    "MergedDir": "/var/lib/docker/overlay2/e463d26f5ef72a58945c059eb5c254617bb9d32395084b8eeec00073a67c1ea4/merged",
                    "UpperDir": "/var/lib/docker/overlay2/e463d26f5ef72a58945c059eb5c254617bb9d32395084b8eeec00073a67c1ea4/diff",
                    "WorkDir": "/var/lib/docker/overlay2/e463d26f5ef72a58945c059eb5c254617bb9d32395084b8eeec00073a67c1ea4/work"
                },
                "Name": "overlay2"
            },
            "Mounts": [],
            "Config": {
                "Hostname": "40efc7830b15",
                "Domainname": "",
                "User": "",
                "AttachStdin": false,
                "AttachStdout": false,
                "AttachStderr": false,
                "ExposedPorts": {
                    "80/tcp": {}
                },
                "Tty": false,
                "OpenStdin": false,
                "StdinOnce": false,
                "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.11",
                    "ASPNET_VERSION=5.0.11"
                ],
                "Cmd": null,
                "Image": "webapi_example",
                "Volumes": null,
                "WorkingDir": "/app",
                "Entrypoint": [
                    "dotnet",
                    "webapi.dll"
                ],
                "OnBuild": null,
                "Labels": {}
            },
            "NetworkSettings": {
                "Bridge": "",
                "SandboxID": "a50cf0bf6b6de541ab199aa760ef4dd277e04a481a1ee31a75084c153e61054f",
                "HairpinMode": false,
                "LinkLocalIPv6Address": "",
                "LinkLocalIPv6PrefixLen": 0,
                "Ports": {
                    "80/tcp": [
                        {
                            "HostIp": "0.0.0.0",
                            "HostPort": "80"
                        }
                    ]
                },
                "SandboxKey": "/var/run/docker/netns/a50cf0bf6b6d",
                "SecondaryIPAddresses": null,
                "SecondaryIPv6Addresses": null,
                "EndpointID": "0a1121d5c992c3800ec03d161d8e901eb8b345a75f3af3fb67af9f196d6fb66e",
                "Gateway": "172.17.0.1",
                "GlobalIPv6Address": "",
                "GlobalIPv6PrefixLen": 0,
                "IPAddress": "172.17.0.3",
                "IPPrefixLen": 16,
                "IPv6Gateway": "",
                "MacAddress": "02:42:ac:11:00:03",
                "Networks": {
                    "bridge": {
                        "IPAMConfig": null,
                        "Links": null,
                        "Aliases": null,
                        "NetworkID": "d0559722735fe10eb946e70ee8e9c52ea7748b40d133c8328842263f50b848e9",
                        "EndpointID": "0a1121d5c992c3800ec03d161d8e901eb8b345a75f3af3fb67af9f196d6fb66e",
                        "Gateway": "172.17.0.1",
                        "IPAddress": "172.17.0.3",
                        "IPPrefixLen": 16,
                        "IPv6Gateway": "",
                        "GlobalIPv6Address": "",
                        "GlobalIPv6PrefixLen": 0,
                        "MacAddress": "02:42:ac:11:00:03",
                        "DriverOpts": null
                    }
                }
            }
        }
    ]
    View Code

    气功波(18037675651)
  • 相关阅读:
    'Specifying a namespace in include() without providing an app_name ' django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing
    ERRORS: <class 'myApp.admin.GradesAdmin'>: (admin.E108) The value of 'list_display[3]'
    TypeError: __init__() missing 1 required positional argument: 'on_delete'
    mysqlclient 1.3.13 or newer is required; you have 0.9.3.
    第一个Tornado程序
    Tornado安装
    MySQL下载与安装
    pycharm安装PyQt框架
    pycharm不能安装第三方库,错误代码Non-zero exit code (1) 的解决办法
    Python相关
  • 原文地址:https://www.cnblogs.com/qgbo/p/15490943.html
Copyright © 2020-2023  润新知