Docker - 將 localhost HTTPS 服務器從容器發佈到主機 (Docker - Publish localhost HTTPS server from container to host)


問題描述

Docker ‑ 將 localhost HTTPS 服務器從容器發佈到主機 (Docker ‑ Publish localhost HTTPS server from container to host)

我已經構建了我的 docker 映像以在本地運行 HTTPS Node.js 服務器,並配置了所有必需的 TLS 證書:

...
var port = config.port || 9010, https;
var tlsOptions = {
    pfx: fs.readFileSync('./tls/keystore.p12'),
    passphrase: ******,
    honorCipherOrder: true,
    secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3    
};
try {
    https = require('https').Server(tlsOptions, app);
} catch (e) {
    console.error('Fail to start HTTPS server ' + e);
}
...

我已經在容器內部以及主機中成功測試了它,使用 curl

我現在將發布容器的 https://localhost:9010 與 docker 主機的 https://localhost:9010 綁定。我使用了以下命令:

docker container run ‑‑publish 9010:9010 ‑‑detach ‑‑name https_server_container https_server:1.0

當我從 docker 的主機(我的本地機器)運行 curl https://localhost:9010時,我收到此錯誤:

curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed

我已嘗試關注 docker doc


參考解法

方法 1:

Way I see it there is some typo with docker command :

docker container run ‑‑publish 9010:9010 ‑‑detach ‑‑name https_server_container https_server:1.0

you need to space( ) between 9010 and ‑‑detach

方法 2:

As indicated by David Maze I changed the server host of my Node.js server runned in the docker container from 127.0.0.1 to 0.0.0.0.

...
https.listen(port, '0.0.0.0', function() {
    ...
});

In this manner I can now reach from my docker host the server in the docker container via https://localhost:9010/.

(by Luca MottaStark JeonLuca Motta)

參考文件

  1. Docker ‑ Publish localhost HTTPS server from container to host (CC BY‑SA 2.5/3.0/4.0)

#tls1.2 #HTTPS #docker #node.js #SSL






相關問題

如何使用 Retrofit 添加 TLS v 1.0 和 TLS v.1.1 (How to add TLS v 1.0 and TLS v.1.1 with Retrofit)

我的 openssl 和 ssl 默認 CA 證書路徑是什麼? (what is my openssl and ssl Default CA Certs Path?)

LDAP 使用端口 389 失敗 (LDAP fails using port 389)

如何配置 Apache 以接受具有 TLS v1.2 的過期客戶端證書? (How configure Apache to accept expired client certificate with TLS v1.2?)

Docker - 將 localhost HTTPS 服務器從容器發佈到主機 (Docker - Publish localhost HTTPS server from container to host)

SChannel 中的密碼套件選擇 (Cipher suite selection in SChannel)

我可以使用任何客戶端證書連接到在容器中運行的 MQTT 代理 (I'm able to connect to MQTT broker running in a container with any client certificate)

如何為通過 Kestrel 服務器託管 PWA 的 UWP 桌面橋應用配置 https (How to configure https for a UWP Desktop Bridge app hosting a PWA via a Kestrel Server)

如何修復 ERR_SSL_VERSION_OR_CIPHER_MISMATCH 錯誤? (How to fix ERR_SSL_VERSION_OR_CIPHER_MISMATCH error?)

在 Apache 2.4.37 中禁用 TLS 1.0 和 1.1 不起作用 (Disabling TLS 1.0 & 1.1 in Apache 2.4.37 not working)

如何從 Windows 解密其他設備(Wifi 熱點)的 TLS 數據包? (How can I decrypt TLS packets of other devices (Wifi Hotspot) from Windows?)

將備用 IP 地址添加到 kubernetes api 服務器 (add alternative IP address to kubernetes api server)







留言討論