通过VM在本地主机上运行Docker容器 [英] Run docker container on localhost via VM

查看:330
本文介绍了通过VM在本地主机上运行Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker和Containers的新手,我试图在容器中运行一个简单的asp.net Web应用程序,但遇到了问题。我的操作系统是Windows 10 Home,因此我必须使用Docker工具箱,该工具箱仅在包含基本Linux操作系统的VM上运行。当我旋转容器时,它似乎可以正常启动,但是我无法在本地主机上查看该应用程序。

I'm new to Docker and Containers, and I'm trying to run a simple asp.net web app in a container but running into issues. My OS is Windows 10 Home, so I have to use the Docker Toolbox, which runs on a VM that only includes a basic Linux OS. When I spin up the container, it seems to start fine, but I can't view the app on the localhost.

$ docker run -p 8342:5000 -it jwarren:project

$ docker run -p 8342:5000 -it jwarren:project

托管环境:生产
内容根路径:/ app
现在正在监听:http:// *:5000
应用程序已启动。按Ctrl + C键关闭。

Hosting environment: Production Content root path: /app Now listening on: http://*:5000 Application started. Press Ctrl+C to shut down.

$ docker ps -a
容器ID图像命令创建的状态端口名称
98cc4aed7586 jwarren:project dotnet运行 8分钟前向上8分钟0.0.0.0:8342->5000/tcp naughty_brattain

$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 98cc4aed7586 jwarren:project "dotnet run" 8 minutes ago Up 8 minutes 0.0.0.0:8342->5000/tcp naughty_brattain

我尝试了一些在网上找到的不同建议,但没有到目前为止已经有所帮助。但是,我对网络的知识非常有限,所以也许我没有完全理解需要做什么。我尝试使用默认的VM计算机IP和容器IP访问它。我知道端口转发不会传递到容器。任何援助将是巨大的,因为这个项目定在星期二,这是完成之前的最后一个障碍。

I've tried several different recommendations that I found on the web, but none have helped so far. However, my knowledge of networking is very limited, so maybe I'm not fully understanding what needs to be done. I've tried accessing it with the default VM machine IP and the container IP. I understand that the port forwarding does not carry over to the container. Any assistance would be great, as this project is due on Tuesday, and this is the last road block before finishing.

推荐答案

我发现以下帖子非常有用:如何从主机外部连接到docker容器(相同的网络)[Windows] 。遵循以下步骤可以很好地工作:

I found the following post that was really helpful: How to connect to a docker container from outside the host (same network) [Windows]. Following the steps below worked perfectly:


  1. 打开Oracle VM VirtualBox Manager

  2. 选择由以下人员使用的VM Docker

  3. 单击设置->网络适配器1(默认设置)为将
    附加到:NAT

  4. 单击高级->端口转发添加规则:协议TCP,主机端口
    8080,访客端口8080(将主机IP和访客IP保留为空)

  1. Open Oracle VM VirtualBox Manager
  2. Select the VM used by Docker
  3. Click Settings -> Network Adapter 1 should (default?) be "Attached to:NAT"
  4. Click Advanced -> Port Forwarding Add rule: Protocol TCP, Host Port 8080, Guest Port 8080 (leave Host IP and Guest IP empty)

您现在应该可以通过localhost:8080和your-internal-ip:8080浏览到您的容器。

You should now be able to browse to your container via localhost:8080 and your-internal-ip:8080.

启动容器(Dockerfile EXPOSES 5000):
docker run -p 8080:5000 -it jwarren:project

Started up the container (Dockerfile EXPOSES 5000): docker run -p 8080:5000 -it jwarren:project

能够连接 http:// localhost:8080

这篇关于通过VM在本地主机上运行Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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