docker - 如何运行 VS 2017 生成的 docker 镜像

标签 docker asp.net-core visual-studio-2017

Docker 新手在这里...

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

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

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

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

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

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

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 command .你会看到类似的东西:

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

您只需要从该镜像运行一个新容器并将其公开的端口映射到本地主机端口。默认情况下,暴露的端口是 80(查看 Dockerfile)。例如:

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

那么您的应用应该可以通过 http://127.0.0.1:1234/ 访问。

解释:

如果设置了 Debug 配置,则 Visual Studio 会创建 empty 不可用的图像。它手动将空容器映射到文件系统,以使调试、“编辑并继续”功能等成为可能。这就是为什么 dev 图像在没有 Visual Studio 的情况下毫无用处。在 Release 配置中构建镜像以使其可用。

文档中描述了完整的发布过程:Visual Studio Tools for Docker

Publishing Docker images

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.

关于docker - 如何运行 VS 2017 生成的 docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43708578/

相关文章:

razor - AddRazorPagesOptions Conventions.AddPageRoute 中的野猫

asp.net-core - VS2017 dotnet core项目代码分析

windows - 将 SSL 证书添加到 Windows Docker 容器

laravel - 在 Heroku 上使用 Apache 部署 Dockerized Laravel 应用程序

mysql - 使用 docker-compose 链接 django 和 mysql 容器

asp.net-core - 红隼服务器 : How to bind different ports to different controllers?

azure - KeyVaultErrorException : Operation returned an invalid status code 'Forbidden'

visual-studio - 在 F# 中键入字符后,Visual Studio 2017 启用完成

c++ - 如何将 VS、C++、OpenGL 应用程序部署到第二台计算机?

docker - 使用docker-compose.yaml的动态crontab