我LocalForward
在通过 SSH 隧道将端口转发到容器时遇到了一些问题。
整个网络是这样的:
这是我Dockerfile
的GW Container
:
FROM ubuntu:latest
RUN apt-get update \
&& apt-get install -y ssh \
&& apt-get clean
EXPOSE 80
COPY config /root/.ssh/config
ENTRYPOINT ["ssh", "app-server", "sleep infinity & wait"]
相关 sshconfig
文件:
Host vpn-gateway
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Hostname 10.20.30.40
User matrix
Host app-server
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Hostname 20.30.40.50
User matrix
ProxyCommand ssh vpn-gateway nc %h %p %r
LocalForward 80 30.40.50.60:1080
现在,我使用docker-compose
以下docker-compose.yml
文件进行容器编排:
version: "3.2"
services:
gateway:
container_name: gateway
image: gateway
build: ./docker/gateway
volumes:
- ~/.ssh/id_rsa:/root/.ssh/id_rsa
- ~/.ssh/id_rsa.pub:/root/.ssh/id_rsa.pub
ports:
- 8080:80
所以,我的想法是,如果我从 localhost 运行 wget:
我会从机器 ( ) 中wget http://127.0.0.1:8080/api/health
得到响应。问题是我被重置了:API Server
30.40.50.60:1080
--2018-06-25 07:19:26-- http://127.0.0.1:8080/api/health
Connecting to 127.0.0.1:8080... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
--2018-06-25 07:19:27-- (try: 2) http://127.0.0.1:8080/api/health
Connecting to 127.0.0.1:8080... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
这可能是由于 Docker 没有看到任何使用端口 80 的应用程序,GW Container
如下所述:https ://serverfault.com/a/769583/292211
如果我跑步,我exec
会得到正确的回应。GW Container
wget http://127.0.0.1:80/api/health
有没有办法欺骗 docker 认为端口 80 可用,GW Container
所以它允许我将端口转发到主机?或者可以以更好的方式处理这些事情中的任何一个吗?所有带有 SSH 隧道的 mumbo-jumbo 都是由于第三方安全限制。
谢谢!