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)

大家都在看

  • 部署solr服务

    前言:请各大网友尊重本人原创知识分享,谨记本人博客:南国以南i 一、S orl单机部署 准备:solr5.5、tomcat8.5、jdk1.8 2.复制./solr-5.5.0/s…

    Linux 2023年6月14日
    0127
  • jenkins

    1. jenkins简介 1.1 SVN介绍 1.2 Maven介绍 1.3 Ant介绍 1.4 Gitdle介绍 1.5 jenkins工作原理 1.6 jenkins特点 2….

    Linux 2023年6月13日
    0148
  • js学习笔记之for循环

    for 循环是在您希望创建循环时经常使用的工具。 for 循环的语法如下: for (语句 1; 语句 2; 语句 3) { 要执行的代码块 } 语句 1 在循环(代码块)开始之前…

    Linux 2023年6月13日
    078
  • std::map自定义类型key

    故事背景:最近的需求需要把一个结构体struct作为map的key,时间time作为value,定义:std::map 技术调研:众所周知,map是STL库中常用的关联式容器,底层…

    Linux 2023年6月13日
    0135
  • 测试计划

    ​ 1.测试计划的定义:描述需要完成的所有工作,包括被测项目的目的、背景、范围、资源、进度、环境、任务、策略,以及相应的风险和措施。 ​ 2.测试计划的作用: 对后面的测试过程起到…

    Linux 2023年6月7日
    079
  • 快速掌握Linux三剑客命令使用

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年6月7日
    0108
  • centos 8及以上安装mysql 8.0

    本文适用于centos 8及以上安装mysql 8.0,整体耗时20分钟内,不需要FQ 1.环境先搞好 systemctl stop firewalld //关闭防火墙 syste…

    Linux 2023年6月7日
    0111
  • 关于Python, ftplib模块中的cwd()进入含中文目录失败的问题

    使用Python的ftplib模块连接ftp服务器时, 使用cwd()连接含中文的目录, 报错 : UnicodeEncodeError: ‘latin-1&#8217…

    Linux 2023年6月6日
    0111
  • Linux下IPC之共享内存的使用方法

    基本参考 《Unix环境高级编程》 第14.9节共享内存来学习。 需要说明的 讲shmget(key,size, flag)函数时,书上大概意识是说, 想访问已有的shm时,key…

    Linux 2023年6月7日
    087
  • 实验1:SDN拓扑实践

    实验1:SDN拓扑实践 基础要求 a) mininet运行结果图 b)2的执行结果截图 2.a)3台交换机,每个交换机连接1台主机,3台交换机连接成一条线。 2.b)3台主机,每个…

    Linux 2023年6月7日
    0108
  • windows下设置redis开机自启动

    windows: 在windows下安装目录下 打开命令窗口: redis-server.exe –service-install redis.windows.conf…

    Linux 2023年5月28日
    0101
  • 记一次vcenter连接esxi失败问题排查(443端口不通)

    vecenter错误 esxi宿主机重启后,vcenter连接esxi提示超时,使用vmware客户端连接esxi也提示超时,开始介入排查。 故障排查 如何进入命令终端 运行alt…

    Linux 2023年6月14日
    082
  • 搭建mount+nfs远程挂载

    需求背景: 192.168.10.100 源服务器 目录:/root/test 目录属主属组普通用户,权限777 192.168.10.111 目标服务器 目录:/root/tes…

    Linux 2023年6月8日
    0110
  • [云原生]Kubernetes-介绍(第1章)

    一、应用部署方式演变 二、Kubernetes简介 三、Kubernetes组件 四、Kubernetes概念 参考: Kubernetes(K8S) 入门进阶实战完整教程,黑马程…

    Linux 2023年6月13日
    0120
  • 真正在大厂干了几年,我学会了反内卷[转]

    内卷这个概念的内涵很丰富,与我们的生活息息相关。为了普及和传播知识,我参考了相关的信息,把我个人的粗浅理解奉献给朋友们。 什么是内卷? 内卷 involution,与之对应的是 e…

    Linux 2023年6月8日
    0122
  • 利用Tensorboard可视化模型、数据和训练过程

    在60分钟闪电战中,我们像你展示了如何加载数据,通过为我们定义的 nn.Module的子类的model提供数据,在训练集上训练模型,在测试集上测试模型。为了了解发生了什么,我们在模…

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