简体   繁体   English

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

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

I would like to publish a .net application in Docker Containers using Visual Studio 2015. 我想使用Visual Studio 2015在Docker容器中发布.net应用程序。

However, at step: Publish. 但是,在步骤:发布。 I didn't see Docker Containers. 我没有看到Docker容器。 在此处输入图片说明

I installed Docker Toolbox, VS2015 Tool for Docker. 我安装了Docker Toolbox和VS2015 Docker工具。

Thanks for your helping. 感谢您的帮助。

I'm not aware of a GUI tool at the moment to publish Docker containers for .NET. 我目前还不知道要为.NET发布Docker容器的GUI工具。 Docker comes from the world of Linux, where much of the work is done on the command-line and manually editing config files. Docker来自Linux领域,其中许多工作在命令行上完成并手动编辑配置文件。 Here is the basic process you need to follow to get a .NET process running in a docker container. 这是要在Docker容器中运行.NET进程所需遵循的基本过程。

HOSTING .NET CORE ON LINUX WITH DOCKER 使用DOCKER在LINUX上托管.NET CORE

Read this! 读这个!

General Docker Process 通用Docker流程

  1. Setup Docker or Docker Toolbox on Windows or Linux (VM running on Virtualbox on your computer is fine for development) 在Windows或Linux上设置Docker或Docker Toolbox(在计算机上的Virtualbox上运行的VM适合开发)
  2. Write a .dockerfile defining your image 编写一个.dockerfile定义您的图像
  3. Get Web API running in a container using docker commands 使用Docker命令获取在容器中运行的Web API

Number 1 I will leave you to follow the instruction for your platform easily found on the Docker website. 第一,我将让您按照Docker网站上容易找到的平台说明进行操作。

Write a dockerfile 编写一个dockerfile

Something like this, to start with: 像这样的东西开始于:

    # 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

Get Web API running in a container 使Web API在容器中运行

Steps: 脚步:

  1. Build and publish your application for the appropriate host environment (windows, ubuntu etc) 为适当的宿主环境(Windows,Ubuntu等)构建和发布您的应用程序
  2. Copy the pubished binaries to an \\app folder below the folder where your dockerfile is located. 将发布的二进制文件复制到dockerfile所在文件夹下的\\ app文件夹中。
  3. Go to the Docker command-line, build and run the container 转到Docker命令行,构建并运行容器

Specify the environments you want to target in your project.json file, and make sure you build and publish your project for the correct environment. 在project.json文件中指定要定位的环境,并确保针对正确的环境构建和发布项目。 For example, we are targeting the containers to run on Ubuntu, so we need to build and publish our binaries for that platform (currently ubuntu.14.04-x64 ). 例如,我们的目标容器是要在Ubuntu上运行,因此我们需要为该平台(当前为ubuntu.14.04-x64buildpublish二进制文件。 This does not work in Visual Studio 2015 Update 3 at this stage, so use the command line. 此操作目前在Visual Studio 2015 Update 3中不起作用,因此请使用命令行。 In your project home directory: 在您的项目主目录中:

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

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

The required binaries are now in the ./bin/Release/Publish folder. 现在,所需的二进制文件在./bin/Release/Publish文件夹中。 The Dockerfile currently requires them in an /app sub-folder of the directory the Dockerfile is in, so Dockerfile当前在Dockerfile所在目录的/ app子文件夹中需要它们,因此

  • copy the published files into your /app folder 将已发布的文件复制到您的/ app文件夹中
  • make sure that a suitable copy of the appsettings.json is prsesent 确保有合适的appsettings.json副本

then in your Docker Quickstart Terminal windows (if using Docker Toolbox, which you seem to be), or the Ubuntu command line run, CD to the folder where your dockerfile is and run: 然后在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>

Now test the API, using the IP address of the docker-machine as returned by docker-machine ip default : 现在使用docker-machine ip default返回的docker-machine ip default的IP地址测试API:

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

This should return the JSON expected. 这应该返回期望的JSON。

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

相关问题 我可以在Docker容器中发布不是ASP.NET 5或ASP.NET Core的.Net应用程序吗? - Can I publish a .Net application which is not ASP.NET 5 or ASP.NET Core in Docker containers? 如何使用Docker容器设置ASP.NET Web应用程序 - How to setup ASP.NET Web Application with Docker container 如何将ASP.NET应用程序部署到Linux服务器上的Docker容器? - How to deploy asp.net application to docker container on Linux server? 如何使用MSBuild发布Asp.NET Web应用程序? - How do I publish a Asp.NET web application using MSBuild? 如何访问我的docker asp.net核心应用程序? - How can I access my docker asp.net core application? 如何以非 root 用户身份在 Kubernetes 中运行 ASP.Net Core 容器? - How do I run an ASP.Net Core container in Kubernetes as non-root user? 我如何在 IIS 中发布 Blazor ASP.NET 应用程序? - How do i publish a Blazor ASP.NET App in IIS? 在 ZC5FD214CDD0D2B3B4272E73B02 容器上使用 IIS 和 asp.net 内核 web 应用程序的最佳实践 - Best Practice to use IIS and asp.net core web application On Docker Container? IIS 8发布ASP.NET核心应用程序 - 正在使用的文件 - IIS 8 publish ASP.NET core application - file in use 我可以进一步减少对由docker容器上的asp.net Web API应用程序运行的docker映像的依赖性 - Can I further reduce dependency on docker images to run by asp.net web api application on docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM