我已经将我的路由器配置为在我的本地计算机ip地址上公开http 80 : ie '192.168.0.79',并且公开了入站和出站ip地址,包括允许通过防火墙。出于本例的目的,我们假设它是"200.200.200.200“
我有一个本地节点服务器运行在这个相同的ip地址上,并且当我访问暴露的ip地址时,我可以看到'hello world‘,例如: 200.200.200.200在我的web浏览器上。这是可行的。
import yargs from 'yargs';
import express from 'express';
const app = express();
const argv = yargs.argv;
const host = argv.host ;
const port = argv.port;
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(port, host, function() {
console.log('listening on ', host, ':', port);
});当我停止节点服务器并在相同的ip地址上运行docker容器时,如下所示:
docker run -p 192.168.0.79:80:8080 -p 50000:50000 --name myjenkins -v %cd%/jenkins:/var/jenkins_home jenkins/jenkins我可以在我的本地机器上看到它,但当尝试从外部when浏览器访问它时,例如:"200.200.200.200“,它只是返回- HTTP错误504
我是否还需要通过docker容器公开其他内容,以使其在网上可见?
我在nginx图像上也遇到了同样的问题。所以我确信我的docker论点中缺少了一些东西。
Dockerfile
FROM nginx:alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY dist /usr/share/nginx/html/dist
COPY nginx/default.conf /etc/nginx/conf.d/docker build -t nginx_image .
docker run -p 192.168.0.79:80:8080 nginx_image发布于 2019-11-15 00:53:59
听起来像是返回路线的问题。登录到您的docker容器,看看是否能ping通8.8.8.8。还要运行netstat -r并查看默认路由是什么。它应该是防火墙的内部IP地址。
发布于 2019-11-15 19:20:17
好的,在很多详尽的研究中,窗口暴露这些容器可能会有问题。或者它可能是关于将这个容器代理到外部的更高级的东西。
我的解决方案。在我的机器上创建一个代理到本地主机的节点服务器。
第1步-获取以太网上此特定台式计算机的ip地址
开始>命令
ipconfig
Ethernet adapter Ethernet 4 (Yours will be different. Which ever is connected to the internet):
...
IPv4 Address. . . . . . . . . . . : 192.168.0.79步骤2-配置路由器、天空路由器或其他路由器,以将此ip暴露给internet
user: admin
pass: sky LAN TCP/IP Setuphelp
IP Address:
192. 168. 0. 1
IP Subnet Mask:
255. 255. 255. 0
TICK - Use Router as DHCP Serverhelp
Starting IP Address:
192. 168. 0. 2
Ending IP Address:
192. 168. 0. 254ip address: 192.168.0.79
Mac adress: (This number will look something like 4c:a2:e0 etc.... - can by got by going to a website and typing whats my ip)
Device Name: (Right click my computer > properties) MYCOMPUTERNAME Service: http: tcp 80
action: allow always
access from: any
0 0 0 0Service: http: tcp 80
action: allow always
Destination IPv4 LAN address: 192.168.0.79
access from: any步骤3-创建一个docker容器(例如jenkins),它将默认为localhost,并在80以外的其他地方公开端口,即81。(我们需要80,才能通过我们的路由器暴露)
在localhost:81上创建
docker run -p 81:8080 -p 50000:50000 --name myjenkins -v %cd%/jenkins:/var/jenkins_home jenkins/jenkins步骤4-创建将公开的ip地址代理到此本地主机的节点服务器或等效服务器
将192.168.0.79重定向到localhost:81的
import express from 'express';
import httpProxy from 'http-proxy';
const app = express();
const host = '192.168.0.79' ;
const port = '80';
const apiProxy = httpProxy.createProxyServer();
app.all('/*', (req, res) => {
console.log('redirecting to docker container - http://localhost:81');
apiProxy.web(req, res, {target: 'http://localhost:81'});
});
app.listen(port, host, function() {
console.log('listening on ', host, ':', port);
});第5步-在step浏览器中键入-我的ip是什么
现在,ipv4将类似于30.132.323.11这样的内容输入到see浏览器中,您应该会看到通过节点服务器代理暴露出来的docker容器。
https://stackoverflow.com/questions/58861897
复制相似问题