Docker部署Dotnet

方法一:打包+镜像 部署

  • 将要部署的项目及其依赖的项目上传至指定文件夹下
  • 要部署的项目添加Docker支持,生成Dockerfile文件
  • 将生成的Dockerfile文件上传至要部署项目的同级根目录下
  • 运行docker build -t net5v20220304 -f Dockerfile .
  • net5v20220304 为构建镜像的镜像名
  • Dockerfile 后面跟着一个 .表示当前目录
  • 如果Dockerfile文件不是放在部署项目的同级根目录下,需要修改Dockerfile文件相应部分代码
docker build --help

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

Options:
      --add-host list           Add a custom host-to-IP mapping (host:ip)
      --build-arg list          Set build-time variables
      --cache-from strings      Images to consider as cache sources
      --cgroup-parent string    Optional parent cgroup for the container
      --compress                Compress the build context using gzip
      --cpu-period int          Limit the CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int           Limit the CPU CFS (Completely Fair Scheduler) quota
  -c, --cpu-shares int          CPU shares (relative weight)
      --cpuset-cpus string      CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string      MEMs in which to allow execution (0-3, 0,1)
      --disable-content-trust   Skip image verification (default true)
  -f, --file string             Name of the Dockerfile (Default is 'PATH/Dockerfile')
      --force-rm                Always remove intermediate containers
      --iidfile string          Write the image ID to the file
      --isolation string        Container isolation technology
      --label list              Set metadata for an image
  -m, --memory bytes            Memory limit
      --memory-swap bytes       Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --network string          Set the networking mode for the RUN instructions during build
                                (default "default")
      --no-cache                Do not use cache when building the image
      --pull                    Always attempt to pull a newer version of the image
  -q, --quiet                   Suppress the build output and print image ID on success
      --rm                      Remove intermediate containers after a successful build (default true)
      --security-opt strings    Security options
      --shm-size bytes          Size of /dev/shm
  -t, --tag list                Name and optionally a tag in the 'name:tag' format
      --target string           Set the target build stage to build.

      --ulimit ulimit           Ulimit options (default [])

第一次运行,报错

runc: symbol lookup error: runc: undefined symbol: seccomp_api_get

大概意思就是缺少依赖包
https://blog.csdn.net/qq_21821091/article/details/115179845
https://blog.csdn.net/Necrolic/article/details/106009382
https://blog.csdn.net/ATOOHOO/article/details/88957596
安装依赖包

yum install libseccomp-devel

安装好之后,继续运行build命令
第一次部署会拉取dotnet基础镜像

  • build成功之后,运行docker run -itd -p 8082:80 net5v20220304
  • -p 8082:80 端口映射 8082-宿主机端口 80-容器端端口 net5v20220304-镜像名称
docker run --help

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

Options:
      --add-host list                  Add a custom host-to-IP mapping (host:ip)
  -a, --attach list                    Attach to STDIN, STDOUT or STDERR
      --blkio-weight uint16            Block IO (relative weight), between 10 and 1000, or 0 to
                                       disable (default 0)
      --blkio-weight-device list       Block IO weight (relative device weight) (default [])
      --cap-add list                   Add Linux capabilities
      --cap-drop list                  Drop Linux capabilities
      --cgroup-parent string           Optional parent cgroup for the container
      --cgroupns string                Cgroup namespace to use (host|private)
                                       'host':    Run the container in the Docker host's cgroup
                                       namespace
                                       'private': Run the container in its own private cgroup
                                       namespace
                                       '':        Use the cgroup namespace as configured by the
                                                  default-cgroupns-mode option on the daemon (default)
      --cidfile string                 Write the container ID to the file
      --cpu-period int                 Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int                  Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int              Limit CPU real-time period in microseconds
      --cpu-rt-runtime int             Limit CPU real-time runtime in microseconds
  -c, --cpu-shares int                 CPU shares (relative weight)
      --cpus decimal                   Number of CPUs
      --cpuset-cpus string             CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string             MEMs in which to allow execution (0-3, 0,1)
  -d, --detach                         Run container in background and print container ID
      --detach-keys string             Override the key sequence for detaching a container
      --device list                    Add a host device to the container
      --device-cgroup-rule list        Add a rule to the cgroup allowed devices list
      --device-read-bps list           Limit read rate (bytes per second) from a device (default [])
      --device-read-iops list          Limit read rate (IO per second) from a device (default [])
      --device-write-bps list          Limit write rate (bytes per second) to a device (default [])
      --device-write-iops list         Limit write rate (IO per second) to a device (default [])
      --disable-content-trust          Skip image verification (default true)
      --dns list                       Set custom DNS servers
      --dns-option list                Set DNS options
      --dns-search list                Set custom DNS search domains
      --domainname string              Container NIS domain name
      --entrypoint string              Overwrite the default ENTRYPOINT of the image
  -e, --env list                       Set environment variables
      --env-file list                  Read in a file of environment variables
      --expose list                    Expose a port or a range of ports
      --gpus gpu-request               GPU devices to add to the container ('all' to pass all GPUs)
      --group-add list                 Add additional groups to join
      --health-cmd string              Command to run to check health
      --health-interval duration       Time between running the check (ms|s|m|h) (default 0s)
      --health-retries int             Consecutive failures needed to report unhealthy
      --health-start-period duration   Start period for the container to initialize before starting
                                       health-retries countdown (ms|s|m|h) (default 0s)
      --health-timeout duration        Maximum time to allow one check to run (ms|s|m|h) (default 0s)
      --help                           Print usage
  -h, --hostname string                Container host name
      --init                           Run an init inside the container that forwards signals and
                                       reaps processes
  -i, --interactive                    Keep STDIN open even if not attached
      --ip string                      IPv4 address (e.g., 172.30.100.104)
      --ip6 string                     IPv6 address (e.g., 2001:db8::33)
      --ipc string                     IPC mode to use
      --isolation string               Container isolation technology
      --kernel-memory bytes            Kernel memory limit
  -l, --label list                     Set meta data on a container
      --label-file list                Read in a line delimited file of labels
      --link list                      Add link to another container
      --link-local-ip list             Container IPv4/IPv6 link-local addresses
      --log-driver string              Logging driver for the container
      --log-opt list                   Log driver options
      --mac-address string             Container MAC address (e.g., 92:d0:c6:0a:29:33)
  -m, --memory bytes                   Memory limit
      --memory-reservation bytes       Memory soft limit
      --memory-swap bytes              Swap limit equal to memory plus swap: '-1' to enable
                                       unlimited swap
      --memory-swappiness int          Tune container memory swappiness (0 to 100) (default -1)
      --mount mount                    Attach a filesystem mount to the container
      --name string                    Assign a name to the container
      --network network                Connect a container to a network
      --network-alias list             Add network-scoped alias for the container
      --no-healthcheck                 Disable any container-specified HEALTHCHECK
      --oom-kill-disable               Disable OOM Killer
      --oom-score-adj int              Tune host's OOM preferences (-1000 to 1000)
      --pid string                     PID namespace to use
      --pids-limit int                 Tune container pids limit (set -1 for unlimited)
      --platform string                Set platform if server is multi-platform capable
      --privileged                     Give extended privileges to this container
  -p, --publish list                   Publish a container's port(s) to the host
  -P, --publish-all                    Publish all exposed ports to random ports
      --pull string                    Pull image before running ("always"|"missing"|"never")
                                       (default "missing")
      --read-only                      Mount the container's root filesystem as read only
      --restart string                 Restart policy to apply when a container exits (default "no")
      --rm                             Automatically remove the container when it exits
      --runtime string                 Runtime to use for this container
      --security-opt list              Security Options
      --shm-size bytes                 Size of /dev/shm
      --sig-proxy                      Proxy received signals to the process (default true)
      --stop-signal string             Signal to stop a container (default "SIGTERM")
      --stop-timeout int               Timeout (in seconds) to stop a container
      --storage-opt list               Storage driver options for the container
      --sysctl map                     Sysctl options (default map[])
      --tmpfs list                     Mount a tmpfs directory
  -t, --tty                            Allocate a pseudo-TTY
      --ulimit ulimit                  Ulimit options (default [])
  -u, --user string                    Username or UID (format: <name|uid>[:<group|gid>])
      --userns string                  User namespace to use
      --uts string                     UTS namespace to use
  -v, --volume list                    Bind mount a volume
      --volume-driver string           Optional volume driver for the container
      --volumes-from list              Mount volumes from the specified container(s)
  -w, --workdir string                 Working directory inside the container

</group|gid></name|uid>
  • docker run 成功后,即可在浏览器上访问了
  • 需要注意的是买的云服务器,需要添加相应端口安全组规则

方法二:docker基础镜像+挂载文件

  • 将要部署的项目发布到文件夹
  • 将发布后的文件上传至linux上
  • 运行docker run -d -p 8084:80 -v /root/demo/publish:/app –workdir /app mcr.microsoft.com/dotnet/aspnet:5.0 dotnet /app/WebCoreDemo.dll
  • /root/demo/publish 为项目发布后的地址(路径)
  • WebCoreDemo.dll 为项目dll文件名
  • 和第一种方式不同的是第一种部署方式缺少dotnet core环境会自动拉取,而第二种方式需要手动拉取,而且需要拉取符合项目dotnet core环境镜像
    • docker pull mcr.microsoft.com/dotnet/aspnet[:version] 手动拉取dotnet core环境命令
    • [:version] 为版本号

运行时出错,可以使用 docker logs +&#x5BB9;&#x5668;ID 命令查看错误日志

docker logs --help
Usage:  docker logs [OPTIONS] CONTAINER
Fetch the logs of a container

Options:
      --details        Show extra details provided to logs
  -f, --follow         Follow log output
      --since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
  -n, --tail string    Number of lines to show from the end of the logs (default "all")
  -t, --timestamps     Show timestamps
      --until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)

STATUS UP 运行成功

[root@iZuf620p8rsr3faul3zsx6Z demo20220324]# docker run -d -p 8084:80 -v /root/demo/publish:/app --workdir /app mcr.microsoft.com/dotnet/aspnet:5.0 dotnet /app/WebCoreDemo.dll
91e887b75afa18e870f6915b91419dd0fb13027a2b7123dc8a91428b0af7bf99
[root@iZuf620p8rsr3faul3zsx6Z demo20220324]# docker ps -a
CONTAINER ID   IMAGE                                  COMMAND                  CREATED          STATUS                        PORTS                  NAMES
91e887b75afa   mcr.microsoft.com/dotnet/aspnet:5.0    "dotnet /app/WebCore&#x2026;"   9 seconds ago    Up 9 seconds                  0.0.0.0:8084->80/tcp   elegant_wing

Original: https://www.cnblogs.com/Dewumu/p/16052681.html
Author: 德乌姆列特
Title: Docker部署Dotnet

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/606536/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 分布式运算中,高精度校时器的畅想

    这是我写的,带有一定的娱乐性质的文章。你可以把它理解为神经病的yy。昨天,我看了个帖子《Facebook工程师开发开源自计时设备 仅需一个PCIe插槽即可工作》,有感而发写了此文。…

    Linux 2023年6月14日
    099
  • 在Linux下使用rm -rf /*后会怎样?

    每个工作过的码农,也许不知道分布式,也许不知道高并发,但想必都知道这句鼎鼎大名的代码。本人对此也是比较好奇的,不妨用虚拟机试试看 首先是普通角色: 普通角色把 拥有权限的文件全都删…

    Linux 2023年6月14日
    0103
  • wait() 进程控制函数实现伪代码

    wait()的实现 父进程调用 wait() wait() { 进入系统调用 sys_wait() sys_wait () { for { x = true for (循环所有就绪…

    Linux 2023年6月7日
    0117
  • GCC编译C:C++的四个过程

    从源码到可执行程序,经历四个过程: 预处理、编译、汇编和链接,前三步由使用编译器来完成、链接由链接来完成。 编译器将编译工作主要分为预处理,编译和汇编三部 连接器的工作是把各个独立…

    Linux 2023年6月13日
    075
  • Liunx-LVM创建与扩容

    LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux 2…

    Linux 2023年6月8日
    0104
  • CentOS 7服务器安装Redis并配置集群(上)

    一、环境准备及规划 3台服务器都是CentOS 7.x,服务器IP如下: 10.223.201.141 ,10.223.201.142,10.223.201.143(这3台作为服务…

    Linux 2023年5月28日
    082
  • 网络设备配置–7、配置单臂路由实现跨vlan通信

    一、前言 同系列前几篇:网络设备配置–1、配置交换机enable、console、telnet密码网络设备配置–2、通过交换机划分vlan网络设备配置&#8…

    Linux 2023年6月8日
    0118
  • Windows下的SSH Server

    (请注意,本文内容以杂谈为主,稍微提及了一些在MobaXterm中开启SSH Server可能遇到的情况和解决方法,没有多少干货,请酌情查看,谢谢) 最近比较无聊,使用MobaXt…

    Linux 2023年6月6日
    0110
  • TCP 和 UDP 协议简介

    一、TCP TCP(Transmission Control Protocol),传输控制协议,对”传输、发送、通信”进行”控制”的…

    Linux 2023年6月16日
    0172
  • java反射机制

    1..获取Class实例的方式 1 @Test 2 public void test3() throws ClassNotFoundException { 3 //方式一:调用运行…

    Linux 2023年6月6日
    0131
  • 我可以不在校园

    我在校园自动打卡,仅作学习使用。 我在校园自动打卡,仅作学习使用 直达电梯:我可以不在校园 posted @2021-11-19 17:38 DominicKK 阅读(258 ) …

    Linux 2023年6月8日
    0115
  • ip、ifconfig 和 route命令介绍与网络配置

    linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者。使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务。ifconfig是net-tools中…

    Linux 2023年6月6日
    0100
  • 小记:音频格式转化ByPython(上)

    近日新买了个耳机,店家附送了一些周董的无损音乐资源,收到货后迫不及待的下载试听,才发现这些资源是wav格式的,导入播放器后歌名、作者、专辑等全是未知,当时想着是不是店家的资源有问题…

    Linux 2023年6月8日
    0115
  • Springboot整合redis

    原文链接:https://blog.csdn.net/SDDDLLL/article/details/103703627 去年学习的Redis,刚刚学习完就迫不及待的在实战中用了一…

    Linux 2023年5月28日
    0107
  • Linux01:常用的基本命令及概述及环境搭建(狂神说)

    Linux学习 一、入门概述 我们为什么要学Linux Linux诞生了这么多年,以前还喊着如何能取代windows系统,现在这个口号已经小多了,任何事物发展都有其局限性都有其天花…

    Linux 2023年5月27日
    077
  • 维修数列代码及简易题解

    总体方案:将左右端点分别转到根和根的右儿子,将目标序列挤到以根的右儿子的左儿子为根的子树中,然后进行一系列骚操作即可 建树:用类似线段树的方法建树,递归即可,注意加两个边界点 插入…

    Linux 2023年6月6日
    0130
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球