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

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

问题描述

Docker 新手在这里...

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 应用程序,并添加了 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 console 命令.你会看到类似的东西:

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 会创建 empty 不可用的图像.它手动将空容器映射到文件系统,以使调试、编辑并继续"功能等成为可能.这就是为什么 dev 图像在没有 Visual Studio 的情况下毫无用处.在 Release 配置中构建映像以使其可用.

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 中心.

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天全站免登陆