Docker 构建NetCore 基础镜像

一般制作docker镜像,都是基于网络同道精心打造的镜像。如果想自己构建一个基础的镜像可以通过此次示例来学习。

学习之路

下载源码并构建docker镜像 

下载地址

说明:

  • 需要切换到项目目录下执行构建命令 docker build -t webapi . 不要忘记命令后的 .
  • 构建命令中的 -t webapi 是给构建镜像起别名

查看制作镜像信息

PS C:\WINDOWS\system32> docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEwebapi latest 5462b957a3e2 About an hour ago 161MB

运行镜像

PS E:\My\docker> docker run -i -t --name webapi -p 6002:6001 webapi /bin/sh/ #

说明:

  • -it 开启容器shell终端
  • --name 给容器起别名
  • -p 主机与容器之间的端口映射
  • /bin/sh 运行容器后进入的工作目录

运行netcore webapi

/ # ls #查看容器目录bin etc lib mnt opt publish run srv tmp vardev home media netcore proc root sbin sys usr/ # cd publish #webapi publish 目录/publish # lsGoogle.Protobuf.dll System.Data.SqlClient.dllMicrosoft.Data.Sqlite.dll System.Security.Cryptography.ProtectedData.dllMySql.Data.dll appsettings.Development.jsonNewtonsoft.Json.dll appsettings.jsonNpgsql.dll runtimesOracle.ManagedDataAccess.dll web.configSQLitePCLRaw.batteries_green.dll webapi.deps.jsonSQLitePCLRaw.batteries_v2.dll webapi.dllSQLitePCLRaw.core.dll webapi.exeSQLitePCLRaw.provider.e_sqlite3.dll webapi.pdbSqlSugar.dll webapi.runtimeconfig.jsonSystem.Configuration.ConfigurationManager.dll

说明:

  • 端口映射后就可以通过主机 localhost:6001 服务webapi站点了
  • 此次webapi示例使用 默认的netcore webapi项目,只是修改了运行示例的接口路径为 api

 

镜像源码https://github.com/eric-projects/docker-net-core 

欢迎打赏

相关文章