简体   繁体   English

将Docker容器(django应用)连接到Windows Lan

[英]Connect docker container (django app) to windows lan

I would like to run a docker in our windows environment so that staff can access the application from their own computers, but cannot get it working. 我想在Windows环境中运行一个docker,以便员工可以从自己的计算机访问该应用程序,但无法使其正常运行。

I have tried both solutions of NAT and bridged mode that were suggested here to no avail: 我已经尝试了NAT和桥接模式的两种解决方案,但都无济于事:

How to connect to a docker container from outside the host (same network) [Windows] 如何从主机外部(同一网络)连接到Docker容器[Windows]

When I use NAT mode, I am able to connect to the app through the localhost of the host computer (127.0.0.1:8000), when I use bridged mode I am able to use the IP of the docker machine (192.168.99.100:8000) but I cannot access them from other computers in the LAN. 当我使用NAT模式时,我可以通过主机的本地主机(127.0.0.1:8000)连接到应用程序,当我使用桥接模式时,我可以使用docker计算机的IP地址(192.168.99.100: 8000),但我无法从LAN中的其他计算机访问它们。

I am able to ping the computer where the docker container is located from another one in the same LAN, but when I type its url into the browser, I get the standard IIS landing page. 我能够从同一局域网中的另一台计算机ping docker容器所在的计算机,但是当我在浏览器中键入其url时,我得到了标准的IIS登陆页面。 I deleted the default site in IIS in case it was taking up the port that I was trying to allocate to the docker container, but that did not work- I simply get a site cannot be reached page. 我删除了IIS中的默认站点,以防它占用了我试图分配给Docker容器的端口,但是那行不通-我只是得到了一个无法访问站点页面。

Ultimately, I just want to be able to access the app in the docker container from another computer inside the LAN on the windows server. 最终,我只想能够从Windows服务器上LAN内的另一台计算机访问docker容器中的应用程序。 Any ideas would be appreciated. 任何想法,将不胜感激。

Edit: I should mention that the person who takes care of the domain LAN, domain controller, said he could set a specific IP address for to connect to the virtualbox (docker container) but does not have any idea of how to do that- he has never heard of docker and unfamiliar with virtualbox. 编辑:我应该提一下,负责域LAN(域控制器)的人说,他可以设置用于连接到virtualbox(docker容器)的特定IP地址,但不知道该怎么做-他从未听说过docker并且不熟悉virtualbox。

What finally worked for me was the following: 最终对我有用的是:

Virtualbox setup 虚拟箱设置

  • I deleted the former virtual env because I was unsure of all of the tinkering I had done to that point 我删除了以前的虚拟环境,因为我不确定自己当时所做的所有修补工作
  • docker-machine create -d virtualbox default # to create new virtual machine docker-machine create -d virtualbox default#创建新的虚拟机
  • power off default virtual machine 关闭默认虚拟机
  • choose settings, network Adapter 3, enable network adapter 选择设置,网络适配器3,启用网络适配器
  • choose bridged network, note the mac address that shows up 选择桥接网络,请注意显示的mac地址
  • set promiscuous mode to allow all 设置混杂模式以允许所有
  • click ok 点击确定
  • docker-machine start default docker-machine启动默认

Virtualbox settings 虚拟箱设置

  • Show the VM screen (either headless start, or show) 显示VM屏幕(无头启动或显示)
  • adduser # this is for the ssh test so strictly not necessary adduser#这是用于ssh测试,因此完全没有必要
  • type ifconfig and find whichever ethernet has the mac address you noted above usually either eth0 or eth1 (also take a look at the inet addr) 输入ifconfig并找到具有您上面提到的mac地址的任何以太网,通常是eth0或eth1(也请查看inet addr)
  • use Putty (from windows) to ssh whateveryourname@inetaddr 使用Putty(从Windows)到ssh whatyourname @ inetaddr
  • type in the password for the user you created, and you should be able to ssh into the VM now - Setting the static IP 输入您创建的用户的密码,您现在应该可以通过SSH进入VM- 设置静态IP
  • in the bash type: sudo ifconfig eth1 netmask 255.255.255.0 在bash类型中:sudo ifconfig eth1 netmask 255.255.255.0
  • type ifconfig to check if it changed - Application 键入ifconfig来检查它是否已更改-应用
  • run your docker-compose script and access the application on staticIP:port# or just staticIP from your LAN depending on how NGINX is setup 运行您的docker-compose脚本,并在staticIP:port#或仅从LAN上的staticIP上访问应用程序,具体取决于如何设置NGINX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM