【发布时间】:2020-01-31 17:16:27
【问题描述】:
我已经构建了我的 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 Protect the Docker daemon socket 但没有。
在容器中正确发布 https 节点服务器应该遵循哪些步骤?
谢谢
【问题讨论】:
-
容器内的服务需要监听0.0.0.0(所有接口),否则无法从容器外访问。您是否设置正确,还是仅在容器私有
localhost上侦听? -
嗨,大卫,非常感谢您的评论。它解决了我的问题!我的 Node.js 服务器监听的是 127.0.0.1 而不是 0.0.0.0,我在 0.0.0.0 中进行了更改,现在我可以从 docker 的主机访问它。
标签: node.js docker ssl https tls1.2