如何运行VS 2017生成的Docker映像 [英] How to run docker image produced by VS 2017

查看:167
本文介绍了如何运行VS 2017生成的Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Docker noob在这里...

Docker noob here...

如何在命令行中正确运行Visual Studio 2017生成的Asp.Net CORE应用程序的docker映像?

How does one properly run the docker image of your Asp.Net CORE app which is produced by Visual Studio 2017 at the command line?

docker run -it -d -p 80:32769 myappimage

似乎无法正常工作(图像运行,但是我无法浏览至我的应用程序)

does not appear to work properly (image runs, but I cannot browse to my app)

注意:我只是使用默认模板在Studio中创建了一个示例ASP.Net Core Web App,并添加了Docker支持(通过单击添加Docker支持"复选框).执行此操作时,Studio会添加一个dockerfile和一些docker-compose文件.

Note: I've simply created a sample ASP.Net Core Web App within Studio using the default template, and added Docker support (by clicking the "Add Docker support" checkbox.). Studio adds a dockerfile and some docker-compose files when you do this.

当Visual Studio运行"图像(按F5键)时-我可以成功浏览到我的应用程序(通过" http://localhost:32789 "或类似的主机端口.容器内的应用位于端口80上).但是我无法弄清楚自己在命令行上运行该命令的方法.

When Visual Studio "runs" the image (by pressing F5) - I can successfully browse to my application ( via "http://localhost:32789" or similar host port. App inside container is on port 80 ). But I cannot figure out the command to run it myself at the command line.

Studio添加到您的项目中的标准Dockerfile是...

The standard Dockerfile that Studio adds to your project is...

FROM microsoft/aspnetcore:1.1
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebApplication2.dll"]

推荐答案

是的,有可能.在 Release 配置中重建您的解决方案,并尝试使用F5运行docker-compose项目,以确保映像已更新并且您的应用正常运行.然后执行docker images 控制台命令.您会看到类似的内容:

Yes, it is possible. Rebuild your solution in the Release configuration and try to run the docker-compose project with F5 to ensure the image is updated and your app is working fine. Then execute docker images console command. You'll see something like:

REPOSITORY   TAG      IMAGE ID       CREATED              SIZE
Your.App     latest   673b79a6bb3d   About a minute ago   294 MB

您需要做的就是从该映像运行一个新容器,并将其公开端口映射到本地主机端口.默认情况下,裸露的端口为80(请参见Dockerfile).例如:

All you need is to run a new container from that image and map its exposed port to a localhost port. By default, the exposed port is 80 (look at Dockerfile). For example:

docker run -d -p 1234:80 --name some_name Your.App:latest

然后您的应用应该可以通过http://127.0.0.1:1234/访问.

Then your app should become accessible at http://127.0.0.1:1234/.

说明:

如果设置了 Debug 配置,则Visual Studio将创建无效图像.它将空容器手动映射到文件系统以进行调试,编辑并继续"功能等.这就是为什么dev图像在没有Visual Studio的情况下无用的原因.在发布配置中构建该图像以使其可用.

If the Debug configuration is set, then empty non-workable images are created by Visual Studio. It manually maps the empty container to the filesystem to make possible debugging, "Edit and Continue" features and so on. This is why dev image is useless without Visual Studio. Build the image in the Release configuration to make it usable.

文档中描述了完整的发布过程:适用于Docker的Visual Studio工具

The full publishing process is described in the documentation: Visual Studio Tools for Docker

发布Docker映像

Publishing Docker images

完成开发和调试周期后, 应用程序,适用于Docker的Visual Studio工具将帮助您创建 您的应用程序的生产映像.将调试下拉菜单更改为 发布并构建应用程序.工具将产生图像 使用:latest标记,您可以将该标记推送到您的私人注册表中,或者 Docker Hub.

Once you have completed the develop and debug cycle of your application, the Visual Studio Tools for Docker will help you create the production image of your application. Change the debug dropdown to Release and build the application. The tooling will produce the image with the :latest tag which you can push to your private registry or Docker Hub.

这篇关于如何运行VS 2017生成的Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆