pr1*_*177 5 docker docker-swarm docker-stack
我创建了一个 docker 堆栈来部署到集群。现在我\xc2\xb4m有点困惑将其部署到真实服务器的正确方法是什么样的?
\n\n当然,我可以
\n\nscp我的docker-stack.yml文件到我的集群的一个节点ssh进入节点docker stack deploy -c docker-stack.yml stackname所以就有了docker-machine我想到的工具。\n我尝试过
docker-machine -d none --url=tcp://<RemoteHostIp>:2375 node1\nRun Code Online (Sandbox Code Playgroud)\n\n只有在没有 TLS 的情况下打开端口时,什么才有效?\n我收到以下内容:
\n\n$ docker-machine env node1\nError checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.178.49:2375": dial tcp 192.168.178.49:2375: connectex: No connection could be made because the target machine actively refused it.\nYou can attempt to regenerate them using \'docker-machine regenerate-certs [name]\'.\nBe advised that this will trigger a Docker daemon restart which might stop running containers.\nRun Code Online (Sandbox Code Playgroud)\n\n我已经尝试生成证书并将其复制到主机:
\n\n ssh-keygen -t rsa\n ssh-copy-id myuser@node1\nRun Code Online (Sandbox Code Playgroud)\n\n然后我跑了
\n\ndocker-machine --tls-ca-cert PathToMyCert --tls-client-cert PathToMyCert create -d none --url=tcp://192.168.178.49:2375 node1 \nRun Code Online (Sandbox Code Playgroud)\n\n结果如下:
\n\n $ docker-machine env node1\n Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "node1:2375": There was an error reading certificate\n You can attempt to regenerate them using \'docker-machine regenerate-certs [name]\'.\n Be advised that this will trigger a Docker daemon restart which might stop running containers.\nRun Code Online (Sandbox Code Playgroud)\n\n我也尝试过使用通用驱动程序
\n\n$ docker-machine create -d generic --generic-ssh-port "22" --generic-ssh-user "MyRemoteUser" --generic-ip-address 192.168.178.49 node1\nRunning pre-create checks...\nCreating machine...\n(node1) No SSH key specified. Assuming an existing key at the default location.\nWaiting for machine to be running, this may take a few minutes...\nDetecting operating system of created instance...\nWaiting for SSH to be available...\nDetecting the provisioner...\nError creating machine: Error detecting OS: OS type not recognized\nRun Code Online (Sandbox Code Playgroud)\n\n如何使用 TLS 正确添加带有 docker-machine 的远程 docker 主机?\n或者是否有更好的方法将堆栈部署到服务器/生产环境?
\n\n我经常读到你应该\xc2\xb4t 公开 docker 端口,但一次都没有公开如何做到这一点。我不能相信他们没有提供一个简单的方法来做到这一点。
\n\n更新及解决方案
\n\n我认为这两个答案都有资格。\n我发现部署到 Azure 官方文档(对于 AWS,它\xc2\xb4s 相同)。\n@Tarun Lalwani 的答案为我指明了正确的方向,它\xc2\xb4s 几乎是官方解决方案。这就是我接受他的答案的原因。
\n\n对我来说以下命令有效:
\n\nssh -fNL localhost:2374:/var/run/docker.sock myuser@node1\nRun Code Online (Sandbox Code Playgroud)\n\n然后你可以运行:
\n\ndocker -H localhost:2374 stack deploy -c stack-compose.yml stackname\nRun Code Online (Sandbox Code Playgroud)\n\n或者
\n\nDOCKER_HOST=localhost:2374\ndocker stack deploy -c stack-compose.yml stackname\nRun Code Online (Sandbox Code Playgroud)\n\n@BMitch 的答案也是有效的,他提到的安全问题不应该被忽略。
\n\n更新2
\n\n@bretf 的答案是连接到您的群体的绝佳方式。特别是如果您有多个的话。它\xc2\xb4s 仍处于测试阶段,但适用于可通过互联网访问的集群,并且\xc2\xb4t 不具有 ARM 架构。
\n即使我正在考虑 TLS,我也不想打开/公开 docker 端口。我宁愿使用 SSH 隧道,然后进行部署
ssh -L 2375:127.0.0.1:2375 myuser@node1
Run Code Online (Sandbox Code Playgroud)
然后使用
DOCKER_HOST=tcp://127.0.0.1:2375
docker stack deploy -c docker-stack.yml stackname
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5387 次 |
| 最近记录: |