mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Update 20160910 HOSTING .NET CORE ON LINUX WITH DOCKER - A NOOB'S GUIDE.md
This commit is contained in:
parent
4b494091c9
commit
a8e11abb81
@ -215,18 +215,23 @@ It didn’t work.
|
||||
Making the same curl request repeatedly, I see one of two errors - either curl: (56) Recv failure: Connection reset by peer or curl: (52) Empty reply from server.
|
||||
重复进行相同请求,我看到了一两个错误:(56)接收失败:连接同等或卷曲复位:(52)来自服务器的空回复。
|
||||
|
||||
|
||||
|
||||
I went back to the docker run documentation and double checked I was using the -p option correctly as well as EXPOSE in the Dockerfile. I couldn’t see the problem and became a bit sad…
|
||||
我返回 docker运行 文件,r然后双重检查我所使用的 -p 选项以及 Docker 文件中的 EXPOSE 指令是否正确。我没有发现任何问题,这让我开始有些伤心。
|
||||
|
||||
After pulling myself together, I decided to consult one of my local DevOps heroes - Dave Wybourn (also mentioned in this post on Docker Swarm). His team had run into this exact problem and the issue was the way that I had (not) configured Kestrel - the new lightweight, cross platform web server used for .NET Core.
|
||||
重新站起来以后,我决定去咨询当地的一个英雄 - Dave Wybourn(他也在文章里提到 Docker Swarm)。他的团队也曾遇到这个实际问题,但问题是,我没有配置过 Kestral - 一个全新的轻量级跨平台 web 服务器,用于 .NET 核心。
|
||||
|
||||
By default, Kestrel will listen on http://localhost:5000. The problem here is that localhost is a loopback interface.
|
||||
默认情况下, Kestrel 会监听 http://localhost:5000。但问题是,这儿的本地主机是一个回路接口。
|
||||
|
||||
From Wikipedia:
|
||||
通过维基百科:
|
||||
|
||||
>In computer networking, localhost is a hostname that means this computer. It is used to access the network services that are running on the host via its loopback network interface. Using the loopback interface bypasses any local network interface hardware.
|
||||
> 在计算机网络中,本地主机是一个象征着这台电脑的主机名。本地主机可以通过网络回路接口访问在主机上运行的网络服务。通过使用回路接口可以绕过任何硬件网络接口。
|
||||
|
||||
This is a problem when running inside a container because localhost can only be reached from within that container. The solution was to update the Main method in Startup.cs to configure the URLs that Kestrel will listen on:
|
||||
在 container 内运行是一个新的问题因为本地主机只能够通过 container 到达。解决方法是更新 Startup.cs 里的主要方法来配置 Kestral 将监听的 URLs:
|
||||
|
||||
```
|
||||
public static void Main(string[] args)
|
||||
@ -244,12 +249,15 @@ public static void Main(string[] args)
|
||||
```
|
||||
|
||||
With this extra configuration in place, I could then rebuild image and run the application in a container which will accept requests from the host:
|
||||
通过这些额外的配置,我可以重建图像,并在 container 中运行应用程序,它将能够接收来自主机的请求:
|
||||
|
||||
|
||||
1. docker build -t niksoper/netcore-books .
|
||||
2. docker run -d -p 5000:5000 niksoper/netcore-books
|
||||
3. curl -i http://localhost:5000/api/books
|
||||
|
||||
I now get the following response:
|
||||
我现在得到下面这些回应:
|
||||
|
||||
```
|
||||
HTTP/1.1 200 OK
|
||||
@ -262,6 +270,7 @@ Server: Kestrel
|
||||
```
|
||||
|
||||
### KESTREL IN PRODUCTION
|
||||
###
|
||||
|
||||
Microsoft’s words:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user