Home >Backend Development >C#.Net Tutorial >Detailed explanation on running ASP.NET Core website in Docker

Detailed explanation on running ASP.NET Core website in Docker

黄舟
黄舟Original
2017-05-28 10:13:391564browse

This article mainly introduces the detailed explanationASP.NET Core website runs in Docker, which is of great practical value. Friends in need can refer to it

Docker, as a new generation of virtualization method, will definitely be widely used in the future. The deployment method of traditional virtual machines must ensure the dependency consistency of development environment, test environment, UAT environment and production environment, which requires a lot of operations. Dimensional human resources, using Docker we can deploy once and run everywhere.

This article introduces how to deploy the ASP.NET Core website to run in Docker.

Software environment list

  1. CentOS 7.3.1611

  2. ## Docker 1.12.6

  3. .NET Core 1.1

InstallationDocker

$ #安装Docker
$ yum install docker
$ #启动docker服务
$ systemctl start docker.service
$ #配置开机启动
$ systemctl enable docker.service

Configuration Docker accelerator

Due to well-known reasons, if you want to use Docker smoothly, you need to configure a Docker accelerator, otherwise you will feel like you have returned to the era of dial-up Internet access.

I use DaoCloud, which is said to be permanently free. The registration address is:
https://account.daocloud.io/signin.

Use WeChat to quickly complete the registration.


After registration is completed, a configuration script address will be provided:


$ #配置docker加速器
$ curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://xxxxxx.m.daocloud.io
$ #重启生效
$ systemctl restart docker

Pull ASP .NET Core image

$ docker pull microsoft/aspnetcore
$ #检查是否成功
$ docker images

Prepare ASP.NET Core website release files

You can refer to my previous article: ASP.NET Core website release to

LinuxServer

Create Dockerfile

and place it in the root directory of the website. The file content is as follows:

FROM docker.io/microsoft/aspnetcore
COPY ./publish
WORKDIR /publish  
EXPOSE 8080
CMD ["dotnet", "TestAspNetCoreWeb.dll"]

Packaging image

$ #注意最后有个点。
$ docker build -t test-netcore:1.0 .

Start container

$ docker run --name test-netcore -p 8080:8080 -d test-netcore:1.0
$ #检查容器是否启动成功,如果启动后没效果,试试docker run 不加-d,如果有报错有提示信息。
$ docker ps

The website runs successfully.

Attachment

During the configuration process, I encountered two situations where the container failed to start:


1. Monitoring use of the website IP, error "Error -99 EADDRNOTAVAIL address not available"


2. The website monitors using localhost, error "curl: (56) Recv failure: Connection

reset by peer”

Finally, I found that using http://*:8080 to monitor was successful.

If you run docker run again after failure, you will be prompted that the name already exists. You can use docker rm -f [container name]

Delete the container or change its name.

The above is the detailed content of Detailed explanation on running ASP.NET Core website in Docker. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn