zoukankan      html  css  js  c++  java
  • net Core 2.2

    CentOS7下使用Docker容器化.net Core 2.2

    一、使用 yum 安装(CentOS 7下) 

     

      Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。

     

      通过 uname -r 命令查看你当前的内核版本

     

      

     

    二、安装 Docker 

     

      从 2017 年 3 月开始 docker 在原来的基础上分为两个分支版本: Docker CE 和 Docker EE。

     

      Docker CE 即社区免费版,Docker EE 即企业版,强调安全,但需付费使用。

     

      1、移除旧的版本 

     

    复制代码
    复制代码
    $ sudo yum remove docker 
                      docker-client 
                      docker-client-latest 
                      docker-common 
                      docker-latest 
                      docker-latest-logrotate 
                      docker-logrotate 
                      docker-selinux 
                      docker-engine-selinux 
                      docker-engine
    复制代码
    复制代码

     

      2、安装一些必要的系统工具

     

    sudo yum install -y yum-utils device-mapper-persistent-data lvm2

     

       3、添加软件源信息

     

    sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

     

       4、更新 yum 缓存

     

    sudo yum makecache fast

     

       5、安装 Docker-ce

     

    sudo yum -y install docker-ce

     

       6、启动 Docker 后台服务 

     

    sudo systemctl start docker

     

       7、测试运行 hello-world 

     

    [root@localhost /]# docker run hello-world

     

       

     

    二、Asp.Net Core2.2 web程序

     

      

     

      dockerfile是你的应用部署到docker上所必须的配置信息,只是个不带扩展名的纯文本文件而已

     

      

     

      设置Makefile属性【始终复制

     

      

     

      Dockerfile内容为

     

    复制代码
    FROM microsoft/dotnet:2.2-aspnetcore-runtime  #基础镜像为dotnetcore
    MAINTAINER demo                    #作者
    
    LABEL description="this is a test website"  #描述
    LABEL version="1.0"                 #描述
    
    WORKDIR /app                    #工作目录
    COPY . .                      #将当前目录下的文件,复制到WORKDIR目录
    EXPOSE 8888                    #容器暴漏8888端口,与上一步设置的端口一致
    ENTRYPOINT ["dotnet","demo.dll"]      #运行容器的命令
    复制代码

     

      修改Program.cs文件

     

    复制代码
    namespace demo
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                CreateWebHostBuilder(args).Build().Run();
            }
    
            public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                    .UseUrls("http://*:8888")
                    .UseStartup<Startup>();
        }
    }
    复制代码

     

      发布,文件系统

     

      默认位置 

     

    demoinRelease
    etcoreapp2.2publish

     

     

     

      

     

    三、构建镜像

     

      1、切换到发布目录  

     

    [root@localhost publish]

     

       2、修改Makefile文件

     

      

     

      指定容器对外暴露端口80。注意,COPY .后面有空格,表示是当前位置,意思是从当前位置复制文件到/publish目录下

     

      3、根据当前目录下dockerfile配置文件,进行打包  

     

    [root@localhost publish]# docker build -t demo .

     

       

     

      4、查看我们打包好的镜像。

     

    [root@localhost publish]# docker images

     

      

     

    四、运行docker容器

     

    [root@localhost publish]# docker run -d -p 8888:8888 demo

     

       -p是进行宿主和容器之间端口的映射,(-p 宿主端口:容器端口)

     

       -d命令,容器就会一直运行,即使关掉终端窗口

     

      检验docker容器是否运行成功

     

      

     

    五、测试

     

      本机要输Centos的IP

     

      

     

      Centos内访问localhost就可以了

     

      

     

    说明

     

      1、配置docker开机启动

     

    systemctl  enable docker

     

       2、确认容器有在运行

     

    [root@localhost /]# docker ps

     

       

     

      CONTAINER ID:容器ID

     

      NAMES:自动分配的容器名称

     

      在容器内使用docker logs命令,查看容器内的标准输出

     

       3、开始/停止容器

     

    [root@localhost /]# docker start/stop  容器id或者容器名

     

       4、重启docker服务,遇到此类错误

     

      

     

      原因是docker服务挂掉了 

     

    systemctl restart docker

     

  • 相关阅读:
    AngularJS Insert Update Delete Using PHP MySQL
    Simple task manager application using AngularJS PHP MySQL
    AngularJS MySQL and Bootstrap Shopping List Tutorial
    Starting out with Node.js and AngularJS
    AngularJS CRUD Example with PHP, MySQL and Material Design
    How to install KVM on Fedora 22
    Fake_AP模式下的Easy-Creds浅析
    河南公务员写古文辞职信
    AI
    政协委员:最大愿望是让小学生步行上学
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/10979127.html
Copyright © 2011-2022 走看看