繁体   English   中英

如何在Docker容器中发布ASP.NET Core应用程序?

[英]How do I publish an ASP.NET Core application in a Docker container?

我想使用Visual Studio 2015在Docker容器中发布.net应用程序。

但是,在步骤:发布。 我没有看到Docker容器。 在此处输入图片说明

我安装了Docker Toolbox和VS2015 Docker工具。

感谢您的帮助。

我目前还不知道要为.NET发布Docker容器的GUI工具。 Docker来自Linux领域,其中许多工作在命令行上完成并手动编辑配置文件。 这是要在Docker容器中运行.NET进程所需遵循的基本过程。

使用DOCKER在LINUX上托管.NET CORE

读这个!

通用Docker流程

  1. 在Windows或Linux上设置Docker或Docker Toolbox(在计算机上的Virtualbox上运行的VM适合开发)
  2. 编写一个.dockerfile定义您的图像
  3. 使用Docker命令获取在容器中运行的Web API

第一,我将让您按照Docker网站上容易找到的平台说明进行操作。

编写一个dockerfile

像这样的东西开始于:

    # Import the appropriate base container supplied by Microsoft
    FROM microsoft/aspnetcore:1.1.0
    # Name your process
    LABEL Name=mercury.docker.core-api Version=1.1.0 
    # Maps a folder on the host machine into the container, naming it SOURCE
    ARG source=./app
    # Creates a folder in the container and makes it the woring folder
    WORKDIR /app
    # Copies you application binaries from where you have put them (see next section) into the container
    COPY $source .
    EXPOSE 80
    ENTRYPOINT dotnet <you-main-app-file>.dll

使Web API在容器中运行

脚步:

  1. 为适当的宿主环境(Windows,Ubuntu等)构建和发布您的应用程序
  2. 将发布的二进制文件复制到dockerfile所在文件夹下的\\ app文件夹中。
  3. 转到Docker命令行,构建并运行容器

在project.json文件中指定要定位的环境,并确保针对正确的环境构建和发布项目。 例如,我们的目标容器是要在Ubuntu上运行,因此我们需要为该平台(当前为ubuntu.14.04-x64buildpublish二进制文件。 此操作目前在Visual Studio 2015 Update 3中不起作用,因此请使用命令行。 在您的项目主目录中:

dotnet build -r ubuntu.14.04-x64 --build-profile --configuration Release

dotnet publish -r ubuntu.14.04-x64 --configuration Release -o ./bin/Release/Publish

现在,所需的二进制文件在./bin/Release/Publish文件夹中。 Dockerfile当前在Dockerfile所在目录的/ app子文件夹中需要它们,因此

  • 将已发布的文件复制到您的/ app文件夹中
  • 确保有合适的appsettings.json副本

然后在Docker Quickstart Terminal窗口中(如果使用的是Docker Toolbox)或运行Ubuntu命令行,则将CD放入dockerfile所在的文件夹并运行:

docker build -t <name_you_want_to_use_for_your_image> .

docker run -d -p 5500:80 -t <name_you_want_to_use_for_your_image>

现在使用docker-machine ip default返回的docker-machine ip default的IP地址测试API:

curl http://<ip-address>:5500/<path appropriate for your api>>

这应该返回期望的JSON。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM