1. windows下安装docker

参考:

https://www.jianshu.com/p/502b4ac536ef

https://docs.docker.com/install/windows/docker-ee/

强烈 推荐 使用windows server 2019

    ____

1、安装

  1. @@@code
  2. 安装Hyper-V
  3. >Install-WindowsFeature -Name Hyper-V
  4.    
  5.  安装容器功能
  6. >Install-WindowsFeature -Name containers
  7.    
  8.  安装完成后需重启服务器
  9. >Restart-computer
  10.    
  11.  >Install-Module DockerMSFTProvider
  12. 提示:不受信任的存储库
  13. (选"Y"确认)
  14.    
  15.  >Install-Package Docker -ProviderName DockerMSFTProvider -Force
  16. (可能会提示包验证错误,安装失败,多试几次即可)
  17.    
  18.  提示:程序来自未标记为"受信任"的程序包源
  19. (选"Y"确认)
  20.    
  21.     
  22.  @@#

注:上述安装很慢的话或者经常出错,可以在C:\Users\Administrator\AppData\Local\Temp\2\DockerMsftProvider下找到DockerDefault_DockerSearchIndex.json,其中有各版本的下 载地址 ,如19.03.2为https://dockermsft.blob.core.windows.net/dockercontainer/docker-19-03-2.zip,手工下载这个文件,放回到DockerMsftProvider目录下,然后执行指令,出现提示后选择"全部(A)"

  1. @@@code
  2. Install-Package Docker -ProviderName DockerMSFTProvider
  3. @@#

   
 

   
 

2、切换linux内核

默认使用windows内核,docker的镜像只能基于nano和servercore,而且 依赖于操作系统的内核,1803,1809,1903等,当然运行一些早期程序会比较适合,推荐的方案是windows 内核的docker搭配一个linux 虚拟 机,在虚拟 机内另外运行一套docker。或者两台服务器各自运行一种内核

如果一定想使用LINUX内核,参考:https://docs.microsoft.com/zh-cn/virtualization/windowscontainers/quick-start/using-insider-container-images

 
 

下列代码以管理员身份 运行powershell逐行复制执行,确保每个指令有明确的输出,如提示被操作 的版本号 。

  1. @@@code
  2. Stop-Service docker
  3. Uninstall-Package docker
  4. Uninstall-Module DockerMsftProvider
  5. Uninstall-Module DockerProvider
  6. #有必要的话上述 代码多执行一遍
  7. Install-Module -Name DockerProvider -Repository PSGallery
  8. Install-Package -Name docker -ProviderName DockerProvider -RequiredVersion Preview
  9. # 或Install-Package -Name docker -ProviderName DockerProvider -RequiredVersion 17.10.0-ee-preview-2
  10. Restart-Computer
  11.    
  12.  切换到Linux内核容器
  13. >[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")
  14. >Restart-Service Docker
  15.    
  16.  切换到Windows内核容器
  17. >[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", $null, "Machine")
  18. >Restart-Service Docker
  19.    
  20.  @@#

切换后重启docker,使用docker info

  1. @@@code
  2. PS C:\Users\Administrator> docker version
  3. Client:
  4. Version: 17.10.0-ee-preview-3
  5. API version: 1.33
  6. Go version: go1.8.4
  7. Git commit: 1649af8
  8. Built: Fri Oct 6 17:52:28 2017
  9. OS/Arch: windows/amd64
  10.    
  11.  Server:
  12. Version: 17.10.0-ee-preview-3
  13. API version: 1.34 (minimum version 1.24)
  14. Go version: go1.8.4
  15. Git commit: b8571fd
  16. Built: Fri Oct 6 18:01:48 2017
  17. OS/Arch: windows/amd64
  18. Experimental: true
  19. PS C:\Users\Administrator>
  20.    
  21.  @@#

   
 

   
 

   
 

3、修改docker配置

启动docker服务后,会生成docker目录 ,文件为C:\ProgramData\docker\config\ daemon.json

  1. @@@code
  2. {
  3. "data-root":"d:\\Docker",
  4. "registry-mirrors": [ "https://i1el1i0w.mirror.aliyuncs.com","https://registry.docker-cn.com"],
  5. "experimental":true
  6. }
  7. @@#

   
 

4、windows内核模式下常用的镜像

拉取非常慢

Windows 2016

docker pull mcr.microsoft.com/windows/servercore:10.0.14393.3204-amd64

   
 

Windows2019 提示版本不对就换TAG

   
 

docker pull mcr.microsoft.com/dotnet/framework/sdk:4.8

docker pull mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-1809

docker pull mcr.microsoft.com/dotnet/core/runtime:2.2-nanoserver-1903

docker pull mcr.microsoft.com/dotnet/core/sdk:2.2.402-nanoserver-1903

docker pull mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1903

docker pull mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1809

docker pull mcr.microsoft.com/windows/servercore:ltsc2019-amd64

       
 

   
 

   
 

   
 

   
 

  1. Linux下安装docker
    1. 安装centos7 mini

安装 docker,参考 https://www.cnblogs.com/qgc1995/p/9553572.html

             
 

  1. @@@code
  2. yum install docker-ce
  3. #安装 19.0.3
  4. @@#

  1. 拉取测试镜像

  1. @@@code
  2. docker pull hello-world
  3. [root@docker ~]# docker run hello-world
  4.              
  5.  Hello from Docker!
  6. This message shows that your installation appears to be working correctly.
  7.              
  8.  To generate this message, Docker took the following steps:
  9. 1. The Docker client contacted the Docker daemon.
  10. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
  11. (amd64)
  12. 3. The Docker daemon created a new container from that image which runs the
  13. executable that produces the output you are currently reading.
  14. 4. The Docker daemon streamed that output to the Docker client, which sent it
  15. to your terminal.
  16.              
  17.  To try something more ambitious, you can run an Ubuntu container with:
  18. $ docker run -it ubuntu bash
  19.              
  20.  Share images, automate workflows, and more with a free Docker ID:
  21. https://hub.docker.com/
  22.              
  23.  For more examples and ideas, visit:
  24. https://docs.docker.com/get-started/
  25.              
  26.  @@#

             
 

             
 

拉取镜像 https://hub.docker.com/publishers/microsoftowner

             
 

参考https://www.bbsmax.com/A/RnJW1E0Bdq/

  1. @@@code
  2. docker pull mcr.microsoft.com/dotnet/core/sdk:2.2
  3. docker images
  4. docker run -itd --rm -p 80:80 --name core_test mcr.microsoft.com/dotnet/core/sdk:2.2
  5. docker ps
  6. docker attach core_test
  7. # 删除tag docker rm core_test 血和泪告诉我们,不要轻易删除tag,这就是一个实例,其中所有文件变动都会删除,如果随后又同名run的话,可以跑路了
  8. # 删除文件 sudo docker rmi imageid
  9. @@#

             
 

             
 

  1. 容器持久化与移除

             
 

  1. 进入docker执行命令

或使用

  1. @@@code
  2. docker inspect -f {{.State.Pid}} 5a406185953b
  3. nsenter --target 20190 --mount --uts --ipc --net --pid
  4. @@#

  1. Docker互访

参考

https://www.cnblogs.com/shenh/p/9714547.html

  1. @@@code
  2. docker network create LanDocker
  3. docker network ls
  4. docker run -itd --rm --name redis --network LanDocker --network-alias redis redis
  5. @@#

           
 

  1. 在vs2017中发布应用

             
 

https://www.cnblogs.com/rufus-hua/p/6742836.html

https://blog.csdn.net/sd7o95o/article/details/80809734

             
 

             
 

  1. @@@code
  2. docker build -t test:1.0 . # 注意最后有一个小点.
  3. docker run -itd -p 80:80 --name test test:1.0 #在浏览器中打开
  4. @@#

             
 

Dockerfile

  1. @@@code
  2. FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS base
  3. WORKDIR /app
  4. copy ./test /app
  5. EXPOSE 80
  6.              
  7.               
  8.  ENTRYPOINT ["dotnet", "WebApplication1.dll"]
  9. @@#

             
 

             
 

             
 

可能发生的错误

             
 

             
 

防火墙操作 参考 https://blog.csdn.net/u013514928/article/details/80411110

  1. @@@code
  2. firewall-cmd --zone=public --add-port=3410-3420/tcp --permanent
  3. firewall-cmd --zone=public --add-port=80/tcp --permanent
  4. firewall-cmd --zone=public --add-port=5880/udp --permanent
  5. firewall-cmd --zone=public --add-port=5881/tcp --permanent
  6. firewall-cmd --zone=public --add-port=5000-5005/tcp --permanent
  7. firewall-cmd --zone=public --add-port=7200/tcp --permanent
  8. firewall-cmd --zone=public --add-port=6379/tcp --permanent
  9. firewall-cmd reload
  10. firewall-cmd --permanent --list-port
  11. @@#

         
 

   
 

         
 

         
 

         
 

附录windows docker常用的管理命令

         
 

https://wenku.baidu.com/view/868c47c36e1aff00bed5b9f3f90f76c661374ce7.html (推荐看一哈通信原理)

         
 

1. 查看docker信息(version、info)

         
 

# 查看docker版本

docker version

         
 

# 显示docker系统的信息

docker info

         
 

2. 对image的操作(search、pull、images、rmi、history)

         
 

# 检索image

docker search image_name

         
 

# 下载image

docker pull image_name

#列出镜像列表; -a, --all=false Show all images; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs

docker images

         
 

# 删除一个或者多个镜像; -f, --force=false Force; --no-prune=false Do not delete untagged parents

docker rmi image_name

         
 

# 显示一个镜像的历史; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs docker his

         
 

3. 启动容器(run)

         
 

docker容器可以理解为在沙盒中运行的进程。这个沙盒包 含了该进程运行所必须的资源,包括文件系统、系统类库、shell 环境等等。但这个沙盒默认是不会运行任何程序的。你需要在沙盒中运行一个进程来启动某一个容器。这个进程是该容器的唯一进程,所以当该进程结束的时候,容 器也会完全的停止。

         
 

# 在容器中运行"echo"命令,输出"hello word"

docker run image_name echo "hello word"

         
 

# 交互式进入容器中

docker run -i -t image_name /bin/bash

         
 

# 在容器中安装新的程序

docker run image_name apt-get install -y app_name

         
 

# 在一次进刚才进入的容器

docker exec -i -t [容器ID]

         
 

Note: 在执行apt-get 命令的时候,要带上-y参数。如果不指定-y参数的话,apt-get命令会进入交互模式,需要用户输入命令来进行确认,但在docker环境中是无法响 应这种交互的。apt-get 命令执行完毕之后,容器就会停止,但对容器的改动不会丢失。

         
 

4. 查看容器(ps)

         
 

# 列出当前所有正在运行的container

docker ps

         
 

# 列出所有的container

docker ps -a

         
 

# 列出最近一次启动的container

docker ps -l

         
 

5. 保存对容器的修改(commit)

         
 

当你对某一个容器做了修改之后(通过在容器中运行某一个命令),可以把对容器的修改保存下来,这样下次可以从保存后的最新状态运行该容器。

         
 

# 保存对容器的修改; -a, --author="" Author; -m, --message="" Commit message

docker commit ID new_image_name

         
 

6. 对容器的操作(rm、stop、start、kill、logs、diff、top、cp、restart、attach)

         
 

# 删除所有容器

docker rm `docker ps -a -q`

         
 

# 删除单个容器; -f, --force=false; -l, --link=false Remove the specified link and not the underlying container; -v, --volumes=false Remove the volumes associated to the container

docker rm Name/ID

         
 

# 停止、启动、杀死一个容器

docker stop Name/ID

docker start Name/ID

docker kill Name/ID

         
 

# 从一个容器中取日志; -f, --follow=false Follow log output; -t, --timestamps=false Show timestamps

docker logs Name/ID

         
 

# 列出一个容器里面被改变的文件或者目录,list列表会显示出三种事件,A 增加的,D 删除的,C 被改变的

docker diff Name/ID

         
 

# 显示一个运行的容器里面的进程信息

docker top Name/ID

         
 

# 从容器里面拷贝文件/目录到本地一个路径

docker cp Name:/container_path to_path

docker cp ID:/container_path to_path

         
 

# 重启一个正在运行的容器; -t, --time=10 Number of seconds to try to stop for before killing the container, Default=10

docker restart Name/ID

         
 

# 附加到一个运行的容器上面; --no-stdin=false Do not attach stdin; --sig-proxy=true Proxify all received signal to the process

docker attach ID

         
 

Note: attach命令允许你查看或者影响一个运行的容器。你可以在同一时间attach同一个容器。你也可以从一个容器中脱离出来,是从CTRL-C。

         
 

7. 保存和加载镜像(save、load)

         
 

当需要把一台机器上的镜像迁移到另一台机器的时候,需要保存镜像与加载镜像。

         
 

# 保存镜像到一个tar包; -o, --output="" Write to an file

docker save image_name -o file_path

         
 

# 加载一个tar包格式的镜像; -i, --input="" Read from a tar archive file

docker load -i file_path

         
 

# 机器a

docker save image_name > /home/save.tar

         
 

# 使用scp将save.tar拷到机器b上,然后:

docker load < /home/save.tar

         
 

8、 登录registry server(login)

         
 

# 登陆registry server; -e, --email="" Email; -p, --password="" Password; -u, --username="" Usernamedocker login

         
 

9. 发布image(push)

         
 

# 发布docker镜像

docker push new_image_name

         
 

10. 根据Dockerfile 构建出一个容器

         
 

#build

--no-cache=false Do not use cache when building the image

-q, --quiet=false Suppress the verbose output generated by the containers

--rm=true Remove intermediate containers after a successful build

-t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success

         
 

docker build -t image_name Dockerfile_path

————————————————

版权声明:本文为CSDN博主「天府云创」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/enweitech/article/details/80689387

      

Docker运行dotnetcore的更多相关文章

  1. 使用docker运行dotnetcore站点

    使用docker运行netcore站点 1.新建一.netcore测试站点,dotnet publish 发布到publish目录下 2.编写Dockerfile文件 3.打包上传到centos服务器 ...

  2. Docker在Linux上运行NetCore系列(一)配置运行DotNetCore控制台

    转发请注明此文章作者与路径,请尊重原著,违者必究. 系列文章:https://www.cnblogs.com/alunchen/p/10121379.html 本篇文章操作系统信息 Linux:ubu ...

  3. 在 Azure 上使用 Docker运行 Mono

    Docker 是最近相当热门的一个名词,它是一个基于 Linux Container 的轻量化的虚拟技术,而微软也相当积极与 Docker 合作,在 Azure 上支持这个火热的技术,并且提供简单的方 ...

  4. Docker运行 Mono

    Docker运行 Mono Docker 是最近相当热门的一个名词,它是一个基于 Linux Container 的轻量化的虚拟技术,而微软也相当积极与 Docker 合作,在 Azure 上支持这个 ...

  5. 如何使用windows版Docker并在IntelliJ IDEA使用Docker运行Spring Cloud项目

    如何使用windows版Docker并在IntelliJ IDEA使用Docker运行Spring Cloud项目 #1:前提准备 1.1 首先请确认你的电脑是windows10专业版或企业版,只有这 ...

  6. Docker 运行Tensorboard 和 jupyter的正确方法

    Docker 运行Tensorboard 和 jupyter的正确方法 网上找了很多方法都是jupyter 运行正常但不知道如何打开Tensorboard.折腾了很久,实验很多中方法最终找到了一个正确 ...

  7. 在Linux(Centos7)上使用Docker运行.NetCore

    在上一篇中我们写了如何在windows中使用docker运行.netcore,既然我们了解了windows下的运行发布,我们也可以试试linux下使用docker运行.netcore项目,那么今天我们 ...

  8. 在Windows上使用Docker运行.NetCore

    今天我们来说下如何在windows下使用docker运行.net core,既然是docker,那么我们首先得在windows上安装docker. 在Windows安装 docker 有两种选择 :1 ...

  9. ASP.NET Core 2.1 使用Docker运行

    重要提示,本文为 ASP.NET Core 2.1 如果你是 2.2 那么请将文中的镜像换为 microsoft/dotnet:2.2.0-aspnetcore-runtime 即可,其他操作一样 1 ...

随机推荐

  1. git删除中间某次提交

    git log获取commit信息 commit 58211e7a5da5e74171e90d8b90b2f00881a48d3a Author: test <test@36nu.com> ...

  2. react-native 相对项目路径导入组件 ___ babel-plugin-module-resolver

    babel-plugin-module-resolver 是一个Babel模块解析插件, 在.babelrc中可以配置模块的导入搜索路径. 为模块添加一个新的解析器.这个插件允许你添加新的" ...

  3. Koa - 初体验(写个接口)

    前言 不会node.js的前端不是一个好前端! 这几年node.js确实是越来越火了,好多公司对node.js都开始有要求.虽说前端不一定要会后端,但想要成为一个优秀的前端,node.js是必经之路. ...

  4. Java中真的只有值传递么?

    Java中真的只有值传递么? (本文非引战或diss,只是说出自己的理解,欢迎摆正心态观看或探讨) 回顾值传递和引用传递 关于Java是值传递还是引用传递,网上有不一样的说法. 1.基本类型或基本类型 ...

  5. 搞清楚Spring Cloud架构原理的这4个点,轻松应对面试

    前言 现在分布式系统基本上都是标配了,如果你现在还在玩儿单机,没有接触过这些东西的话,权当是为你打开一扇新的大门吧. 大的单体项目 以前我们做单机系统的时候,所有的代码都在一个项目里面,只是不同的模块 ...

  6. 《Java基础知识》Java集合(Collection)

    作为一个Developer,Java集合类是我们在工作中运用最多的.最频繁的类.相比于数组(Array)来说,集合类的长度可变,更加适合于现代开发需求: Java集合就像一个容器,可以存储任何类型的数 ...

  7. WebGPU学习(六):学习“rotatingCube”示例

    大家好,本文学习Chrome->webgpu-samplers->rotatingCube示例. 上一篇博文: WebGPU学习(五): 现代图形API技术要点和WebGPU支持情况调研 ...

  8. JavaFX如何为按钮设置快捷键?

    JavaFX为按钮设置快捷键的方式有很多,先说下常见的一种. 第一种: KeyCodeCombination kc1 = new KeyCodeCombination(KeyCode.W, KeyCo ...

  9. 内网渗透教程大纲v1.0

    内网渗透 ☉MS14-068(CVE-2014-6324)域控提权利用及原理解析 ☉域控权限提升PTH攻击 未完待续...

  10. android只设置部分控件随着软键盘的出现而腾出空间

    转载请标明出处:https://www.cnblogs.com/tangZH/p/12013685.html 在项目过程中,出现了一个需求,软键盘要顶起部分控件,而另一部分控件不动. 关于这种需求,我 ...