Docker installation and deployment examples .Net Core

1. What is the Docker

Docker is an open source application container engine that lets developers can package their applications as well as a portable container to the dependencies, and then posted to any popular Linux machine, can be virtualized. The container is full use of the sandbox mechanism will not have any interface with each other.

2. Why Docker

Docker containers using technology applications and services can be published again the whole platform. As we know, .Net platform has been because it is not open source and cross-platform is not criticized. Xiao Bian is a loyal Microsoft powder, but can not use Linux as a server entity .Net platform now everywhere in distributed systems, micro-services aspect of the world, is really difficult. Fortunately, there is a Docker container technology to solve this problem, so small series by a lot of leisure time to fill the pit, also deployed out here to share with you.

PS: Why not use other ways (dependent frameworks) to publish .NetCore application on linux. A full platform can be used to configure it! That goes without saying, ah, handsome ah! ! ! !

3. Install Docker

There are many ways to install Docker, Xiao Bian also tried several, but because of speed restrictions on domestic and some way will be very slow, or even suspended because of too slow to download. And there are some ways you install a lot of problems, Xiao Bian also to share their own experience here for everyone to pit.

Here to share with two installation methods, the measured effective. Docker two versions, and ce-Docker Docker-ee, which is charged, small version here and ce.

(1) installed with yum    

Install the necessary system tools: PS: sudo expressed execute with administrator privileges, the case of the root user (the highest authority) may enter

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

Add the software source information:

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

Update yum cache:

$ sudo yum makecache fast

Installation Docker-ce:

$ sudo yum -y install docker-ce

Docker start background service

$ sudo systemctl start docker

Hello-world test run

$ docker run hello-world

(2) using a script to install Docker eat network speed, fast speed select

Ensure that the yum package up to date.

$ sudo yum update

Docker execute the installation script.

$ curl -fsSL https://get.docker.com -o get-docker.sh

$ sudo sh get-docker.sh

Docker start the process.

$ sudo systemctl start docker

Docker verify successful installation and execution of a test image in the container

$ sudo docker run hello-world

(3) Docker Common Commands

$ Docker pull mirror name // pull mirror, I want to deploy the application you may need to rely on some basic mirror

$ Docker build a custom image name. // compile a mirror image of their own projects, deployed to Docker container, do not forget this. ''! ! !

$ Docker images // Check all mirrors

$ Docker run --name = name -p host environment container port: Docker container port mapping mirroring name -d // run-time image

$ Docker ps -a // View container running state, up running success

$ Docker logs -t -f container name // View the Run Log, you can learn to see problems

4. Deployment .NetCore applied to Docker

(1) Create a new ASP.NET Core 3.0 project

 

 

Then run the project, to ensure that we have just created the project can run properly

(2) prepare Dockerfile, and set the property to generate a file copy

FROM microsoft/dotnet:3.0-aspnetcore-runtime

RUN cd /usr/local/src 

RUN mkdir MyTestApi 

WORKDIR /usr/local/src/MyTestApi

COPY . . 

EXPOSE 80 

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

(3)发布项目

 

(4)将Dockerfile文件复制到发布成功的目录,并全部上传到服务器

 

(5)构建Docker镜像

进入到发布文件目录(Dockerfile文件所在目录),执行命令便可打包镜像

$ docker pull microsoft/dotnet:3.0-aspnetcore-runtime        //拉取基础镜像

$ docker build -t mytestapi .            //构建镜像  别忘了这个点“.”!!!

$ docker run --name=mytestapi -p 80:5000 -d  mytestapi        //运行镜像

出现一长串字符串,便是表示运行成功

 

5.部署.NetCore到Docker遇到的问题

 

 
 

6.总结

到这里呐今天的内容就到此结束了,感觉大家翻阅。

Guess you like

Origin www.cnblogs.com/valu/p/11596593.html