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)

大家都在看

  • 杨辉三角的变形—牛客网

    杨辉三角的变形_牛客题霸_牛客网 (nowcoder.com) #include using namespace std; int main() { //这个树的偶数规律为 -1 …

    Linux 2023年6月13日
    0117
  • Linux IP 命令略解

    help 为该命令的帮助信息。 实例ip link show # 显示网络接口信息 ip link set eth0 up # 开启网卡 ip link set eth0 down…

    Linux 2023年6月14日
    080
  • 国产化之Arm64 CPU+银河麒麟系统安装.NetCore

    背景 某个项目需要实现基础软件全部国产化,其中操作系统指定银河麒麟,银河麒麟就是一个Linux发行版,数据库使用达梦V8,这个数据库很多概念和Oracle相似,CPU平台的范围:龙…

    Linux 2023年5月27日
    074
  • CentOS——Redis远程连接可视化工具Rdis Desktop Manage

    前排提示 Centos没有安装Redis的可参考 https://www.cnblogs.com/tianhengblogs/p/15265028.html 一。 修改redis….

    Linux 2023年5月28日
    0161
  • kafka能做什么?kafka集群配置 (卡夫卡 大数据)

    什么是Kafka 官网介绍: 几个概念: 详细介绍 : 操作kafka: kafka集群 消息测试 问题检测 什么是Kafka 官网介绍: ApacheKafka®是一个分布式流媒…

    Linux 2023年6月7日
    0122
  • Mysql在linux对大小写敏感的设置

    编辑/etc/my.cnf文件,在[mysqld]节下 添加 lower_case_table_names 参数,并设置相应的值 (备注:为0时大小写敏感,为1时大小写不敏感,默认…

    Linux 2023年6月13日
    089
  • Docker基本命令

    第一次使用docker,从helle world开始 docker run hello-world 镜像的完整写法:[仓库地址/]镜像名[:版本号] –help 查看帮…

    Linux 2023年6月13日
    0102
  • 计算机系统领域学术会议论文评审流程

    今天看到海波老师的一张图,进行转载一下,下图记录了SOSP, OSDI, Eurosys 等计算机系统顶会的评审流程: 保持更新;cnblogs.com/xuyaowen。 Ori…

    Linux 2023年6月14日
    082
  • Jenkinsfile Pipeline 使用 SSH 连接

    为了在 Jenkinsfile 的命令中使用 SSH,我们不得不通过一些设置… 前提 首先你需要将用到的 SSH 私钥保存到 Jenkins 的凭据中,这样你会获得一个…

    Linux 2023年6月7日
    0111
  • Java对象序列化和反序列化

    Java类的序列化和反序列化 序列化:指将对象转换为字节序列的过程,也就是将对象的信息转换成文件保存。 反序列化:将字节序列转换成目标对象的过程,也就是读取文件,并转换为对象。 几…

    Linux 2023年6月14日
    099
  • Golang 实现 Redis(4): AOF 持久化与AOF重写

    AOF 持久化是典型的异步任务,主协程(goroutine) 可以使用 channel 将数据发送到异步协程由异步协程执行持久化操作。 在 DB 中定义相关字段: type DB …

    Linux 2023年5月28日
    095
  • 微信小程序转uniapp

    微信小程序转uniapp 安装包 cnpm install miniprogram-to-uniapp -g 查看版本 wtu -V 转化执行 wtu -i 要转化的小程序目录 例…

    Linux 2023年6月7日
    088
  • RedisInsight 安装与使用(Redis 监控工具)【转】

    一、RedisInsight 简介 RedisInsight 是一个直观高效的 Redis GUI 管理工具,它可以对 Redis 的内存、连接数、命中率以及正常运行时间进行监控,…

    Linux 2023年5月28日
    093
  • shell生成指定长度的随机数

    生成指定长度是随机数 8位纯数字的随机数 tr -cd ‘0-9’ 使用/dev/urandom而不是/dev/random是因为后者比较慢。 Original: https://…

    Linux 2023年5月28日
    0104
  • @EnableFeignClients注解源码解析

    转载请注明出处: @EnableFeignClients 注解定义的源码 这个注解通过@Import注解导入一个配置类FeignClientsRegistrar.class ;Fe…

    Linux 2023年6月14日
    092
  • Shell脚本编程初体验

    通常,当人们提到”shell脚本语言”时,浮现在他们脑海中是bash,ksh,sh或者其它相类似的linux/unix脚本语言。脚本语言是与计算机交流的另外…

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