[英]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进程所需遵循的基本过程。
Number 1 I will leave you to follow the instruction for your platform easily found on the Docker website. 第一,我将让您按照Docker网站上容易找到的平台说明进行操作。
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
Steps: 脚步:
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-x64
) build
并publish
二进制文件。 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子文件夹中需要它们,因此
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.