This article mainly introduces the detailed description of the ASP. NET Core website running in Docker, very practical value, the need for friends can refer to the following
Docker as a new generation of virtualization, the future will certainly be widely used, the traditional virtual machine deployment way to ensure that the development environment, test environment, UAT environment, production environment dependence consistency, requires a large number of operations and maintenance of manpower, using Docker we can implement a deployment, run everywhere.
This article describes how to deploy an ASP. NET core site to run in Docker.
Software Environment Checklist
CentOS 7.3.1611
Docker 1.12.6
. NET Core 1.1
Installing Docker
$ #安装Docker $ yum Install docker$ #启动docker服务 $ systemctl start docker.service$ #配置开机启动 $ systemctl Enable Docker.service
Configuring the Docker Accelerator
For well-known reasons, if you want to use Docker smoothly, you'll need to configure the Docker accelerator, or you'll feel like you're back in the dial-up internet era.
I use Daocloud, which is called permanent free. The registered address is: Https://account.daocloud.io/signin.
You can quickly complete your registration with a sweep.
Registration completion will provide a configuration script address:
$ #配置docker加速器 $ Curl-ssl https://get.daocloud.io/daotools/set_mirror.sh | Sh-s http://xxxxxx.m.daocloud.io$ #重启生效 $ systemctl Restart Docker
Pull the ASP. NET Core Image
$ docker Pull microsoft/aspnetcore$ #检查是否成功 $ docker Images
Preparing the ASP. NET core Web site publishing file
You can refer to my previous article: ASP. NET Core website published to Linux server
Create Dockerfile
To the Web site root directory, the file content is as follows:
From Docker.io/microsoft/aspnetcorecopy./publishworkdir/publish EXPOSE 8080CMD ["Dotnet", " TestAspNetCoreWeb.dll "]
Package image
$ #注意最后有个点. $ docker build-t test-netcore:1.0.
Start container
$ docker Run--name test-netcore-p 8080:8080-d test-netcore:1.0$ #检查容器是否启动成功, if no effect after startup, try Docker run without D, if there is an error message. $ docker PS
The site is running successfully.
Report
The configuration process I encountered two scenarios in which the container failed to start:
1. The website listens to use the IP, the error "Error-99 Eaddrnotavail address Not available"
2. Web monitoring using localhost, error "Curl: (RECV) failure:connection reset by Peer"
Finally found the use of http://*:8080 to monitor the success.
The Docker run fails again after the prompt name already exists, you can use Docker Rm-f [container name] to remove the container or change the name.