首页 > 其他分享 >.net6 docker部署,以及问题解决(附Dokerfile)

.net6 docker部署,以及问题解决(附Dokerfile)

时间:2023-03-18 23:56:36浏览次数:85  
标签:src RUN Web list MyProject sources Dokerfile net6 docker

搭建仓库,发布配置

docker搭建私有仓库

参考上文,搭建好私有仓库,成功访问http://127.0.0.1:5000/v2/_catalog之后:

  1. 在VS右键 => 添加 => Docker支持 => 选择Linux,即可自动添加Dokerfile
  2. 在VS右键发布 => Docker容器注册表 => 其他Docker容器注册表 => 注册表URL:http://localhost:5000
  3. 发布配置:

部署模式选择独立或者框架依赖都可以,如果选择框架依赖,那么启动项目时,需要运行.net6的容器。

启动容器的问题以及相应解决方法

1. System.Drawing.Common is not supported on non-Windows platforms.

仅在 Windows 上支持 System.Drawing.Common
简单说就是有两种解决方法:

  1. 将引用System.Drawing.Common的代码改为其他类库
  2. 新增一个runtimeconfig.template.json 模板文件:

2. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.

System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibgdiplus: cannot open shared object file: No such file or directory

需要在容器中安装libgdiplus,可在dockerfile中添加如下代码:

WORKDIR /etc/apt
# 备份
RUN mkdir sources.list.backup
RUN cp sources.list ./sources.list.backup
# 以覆盖+追加的方式替换掉sources.list文件(解决下载慢问题)
RUN echo 'deb https://mirrors.aliyun.com/debian bullseye main'>sources.list
RUN echo 'deb https://mirrors.aliyun.com/debian-security bullseye-security main'>>sources.list
RUN echo 'deb https://mirrors.aliyun.com/debian bullseye-updates main'>>sources.list
#RUN cat sources.list
RUN apt-get update -y
RUN apt-get install -y libgdiplus

3. Cannot find any fonts in specified font sources.

  1. 到windows系统的C://windows/Fonts目录下寻找字体,将找到的字体和Dockerfile文件放在同一级目录下
  2. 在dockerfile中添加如下代码:
COPY ["src/myProject/simkai.ttf", "/usr/share/fonts/simkai.ttf"]  
COPY ["src/myProject/SimSun.ttf", "/usr/share/fonts/SimSun.ttf"]

4. RedisConnectionException: It was not possible to connect to the redis server(s).

修改redis.windows-service.conf,增加ip地址配置(192.168.5.22为主机的ip):

bind 127.0.0.1 192.168.5.22

完整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:6.0 AS base
WORKDIR /app
EXPOSE 21234

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src

COPY ["src/MyProject.Web.Host/MyProject.Web.Host.csproj", "src/MyProject.Web.Host/"]
COPY ["src/MyProject.Web.Core/MyProject.Web.Core.csproj", "src/MyProject.Web.Core/"]
COPY ["src/MyProject.Application/MyProject.Application.csproj", "src/MyProject.Application/"]
COPY ["src/MyProject.Core/MyProject.Core.csproj", "src/MyProject.Core/"]
COPY ["src/MyProject.EntityFrameworkCore/MyProject.EntityFrameworkCore.csproj", "src/MyProject.EntityFrameworkCore/"]
RUN dotnet restore "src/MyProject.Web.Host/MyProject.Web.Host.csproj"
COPY . .
WORKDIR "/src/src/MyProject.Web.Host"
RUN dotnet build "MyProject.Web.Host.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "MyProject.Web.Host.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
#RUN cd /etc/apt
WORKDIR /etc/apt
# 备份
RUN mkdir sources.list.backup
RUN cp sources.list ./sources.list.backup
# 以覆盖+追加的方式替换掉sources.list文件
RUN echo 'deb https://mirrors.aliyun.com/debian bullseye main'>sources.list
RUN echo 'deb https://mirrors.aliyun.com/debian-security bullseye-security main'>>sources.list
RUN echo 'deb https://mirrors.aliyun.com/debian bullseye-updates main'>>sources.list
#RUN cat sources.list
RUN apt-get update -y
RUN apt-get install -y libgdiplus

WORKDIR /app
COPY --from=publish /app/publish .

COPY ["src/MyProject.Web.Host/simkai.ttf", "/usr/share/fonts/simkai.ttf"]
COPY ["src/MyProject.Web.Host/SimSun.ttf", "/usr/share/fonts/SimSun.ttf"]
COPY ["src/MyProject.Web.Host/times.ttf", "/usr/share/fonts/times.ttf"]
COPY ["src/MyProject.Web.Host/timesbd.ttf", "/usr/share/fonts/timesbd.ttf"]
COPY ["src/MyProject.Web.Host/timesbi.ttf", "/usr/share/fonts/timesbi.ttf"]
COPY ["src/MyProject.Web.Host/timesi.ttf", "/usr/share/fonts/timesi.ttf"]

ENTRYPOINT ["dotnet", "MyProject.Web.Host.dll"]

标签:src,RUN,Web,list,MyProject,sources,Dokerfile,net6,docker
From: https://www.cnblogs.com/cnblogsName/p/17130616.html

相关文章

  • CentOS docker 搭建nginx访问宿主机端口报错curl: (56) Recv failure: Connection res
    https://www.jianshu.com/p/a21e8e8e54dd 在正常安装docker-ce环境后尝试运行nginx测试docker环境是否正常,结果发现docker容器映射到宿主机的端口无法正常访问报错......
  • docker 安装redis
    dockersearchredis   或者去dockerHub上去找版本哪个版本用的人多就用哪个 2.dockerpulredis(dockerpull<镜像名称>:<版本号>默认是拉取latest)  ......
  • docker镜像转存脚本
    #需要有外网服务器!!!#!/bin/bashecho-e"\E[0;41m私有仓库需要提前登录!!\E[0m\n"checkEv(){if[$1==0];thenecho-e"\E[0;42mok!!!!\E[0m\n"else......
  • Docker安装Mysql
    使用Docker安装MySQL拉取MySQL镜像dockerpullmysql:(version)eg:dockerpullmysql:5.7创建数据目录#创建数据存放目录mkdir/home/env/db/data/mysql#创......
  • docker加入用户组
    1.创建docker用户组sudogroupadddocker2.应用用户加入docker用户组sudousermod-aGdocker${USER}3.重启docker服务sudosystemctlrestartdocker4.切......
  • how to install and use docker in ubuntu20.04
    sudoapt-getremovedockerdocker-enginedocker.iocontainerdrunc安装Docker之前,确保之前安装的Docker已经删除。这行命令是为了卸载系统上已经安装的Docker引......
  • linux系统离线安装docker(分步法&一键法)
    https://blog.csdn.net/chexlong/article/details/127932711 1前言在有的项目场景中,服务器是不允许连接外网的。此时若想在服务器上安装部署docker容器,就不能采用在......
  • mac m1 docker 安装kafka和zookeeper
    获取本地ip地址  ifconfigen0  192.168.31.35.  这边的ip地址在下面的ip会使用到拉取镜像dockerpullwurstmeister/zookeeperdockerpullwurstmeister/kafka......
  • CentOS Docker安装、镜像加速
    CentOSDocker安装方法一:使用官方安装脚本自动安装#安装命令:curl-fsSLhttps://get.docker.com|bash-sdocker--mirrorAliyun#使用国内daocloud一键安装命令:c......
  • docker 常用工具
    windows下常常需要linux环境直接安装虚拟机不方便也浪费资源所以直接在docker下安装一个centos然后搭建好开发环境就是个不错的办法一、Linux环境1、安装centos(默......