Docker运行dotnetcore

         

  1. 安装centos7 mini

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

         

@@@code

yum install docker-ce

#安装 19.0.3

@@#

  1. 拉取测试镜像

@@@code

docker pull hello-world

[root@docker ~]# docker run hello-world

         

Hello from Docker!

This message shows that your installation appears to be working correctly.

         

To generate this message, Docker took the following steps:

1. The Docker client contacted the Docker daemon.

2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

(amd64)

3. The Docker daemon created a new container from that image which runs the

executable that produces the output you are currently reading.

4. The Docker daemon streamed that output to the Docker client, which sent it

to your terminal.

         

To try something more ambitious, you can run an Ubuntu container with:

$ docker run -it ubuntu bash

         

Share images, automate workflows, and more with a free Docker ID:

https://hub.docker.com/

         

For more examples and ideas, visit:

https://docs.docker.com/get-started/

         

@@#

         

         

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

         

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

@@@code

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

docker images

docker run -itd --rm -p 80:80 --name core_test mcr.microsoft.com/dotnet/core/sdk:2.2

docker ps

docker attach core_test

# 删除tag docker rm core_test 血和泪告诉我们,不要轻易删除tag,这就是一个实例,其中所有文件变动都会删除,如果随后又同名run的话,可以跑路了

# 删除文件 sudo docker rmi imageid

@@#

         

Docker运行dotnetcore_第1张图片

         

  1. 容器持久化与移除

Docker运行dotnetcore_第2张图片

         

  1. 进入docker执行命令

或使用

@@@code

docker inspect -f {{.State.Pid}} 5a406185953b

nsenter --target 20190 --mount --uts --ipc --net --pid

@@#

  1. Docker互访

参考

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

@@@code

docker network create LanDocker

docker network ls

docker run -itd --rm --name redis --network LanDocker --network-alias redis redis

@@#

       

  1. 在vs2017中发布应用

         

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

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

         

         

@@@code

docker build -t test:1.0 . # 注意最后有一个小点.

docker run -itd -p 80:80 --name test test:1.0 #在浏览器中打开

@@#

         

Dockerfile

@@@code

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS base

WORKDIR /app

copy ./test /app

EXPOSE 80

         

         

ENTRYPOINT ["dotnet", "WebApplication1.dll"]

@@#

Docker运行dotnetcore_第3张图片

         

         

Docker运行dotnetcore_第4张图片

         

可能发生的错误

         

         

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

@@@code

firewall-cmd --zone=public --add-port=3410-3420/tcp --permanent

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=5880/udp --permanent

firewall-cmd --zone=public --add-port=5881/tcp --permanent

firewall-cmd --zone=public --add-port=5000-5005/tcp --permanent

firewall-cmd --zone=public --add-port=7200/tcp --permanent

firewall-cmd --zone=public --add-port=6379/tcp --permanent

firewall-cmd –reload

firewall-cmd --permanent --list-port

@@#

     

Windows2016中安装docker

参考:

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

net stop docker

net start docker

Docker运行dotnetcore_第5张图片

     

修改镜像路径C:\ProgramData\docker

参考:https://docs.microsoft.com/zh-cn/virtualization/windowscontainers/manage-docker/configure-docker-daemon

@@@code

{

"data-root":"d:\\Docker",

"registry-mirrors": [ "https://i1el1i0w.mirror.aliyuncs.com","https://registry.docker-cn.com"]

}

@@#

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

   

Windows2016

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

     

     

     

     

附录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)