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 的主机(我的本地计算机)运行 卷曲 https://localhost:9010
时,我收到此错误:
curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed
我试图遵循 docker 文档 Protect the Docker daemon socket 但什么也没有。
在容器中正确发布https节点服务器应该遵循哪些步骤?
谢谢
据我所知,docker 命令有一些拼写错误:
docker container run --publish 9010:9010 --detach --name https_server_container https_server:1.0
您需要 space( ) 在 9010 和 --detach
之间
如 David Maze 所示,我将在 docker 容器中运行的 Node.js 服务器的服务器主机从 127.0.0.1
更改为 0.0.0.0
。
...
https.listen(port, '0.0.0.0', function() {
...
});
通过这种方式,我现在可以通过 https://localhost:9010/ 从我的 docker 主机访问 docker 容器中的服务器。
我已将我的 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 的主机(我的本地计算机)运行 卷曲 https://localhost:9010
时,我收到此错误:
curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed
我试图遵循 docker 文档 Protect the Docker daemon socket 但什么也没有。
在容器中正确发布https节点服务器应该遵循哪些步骤?
谢谢
据我所知,docker 命令有一些拼写错误:
docker container run --publish 9010:9010 --detach --name https_server_container https_server:1.0
您需要 space( ) 在 9010 和 --detach
之间如 David Maze 所示,我将在 docker 容器中运行的 Node.js 服务器的服务器主机从 127.0.0.1
更改为 0.0.0.0
。
...
https.listen(port, '0.0.0.0', function() {
...
});
通过这种方式,我现在可以通过 https://localhost:9010/ 从我的 docker 主机访问 docker 容器中的服务器。