Docker Machine

Machine 是什么、为什么已被取代,以及用 Docker context 管理远程主机的现代做法。

Intermediate
Key PointsMachine 用来在远程主机上装 Docker 并生成客户端证书;它已停止维护,现在用 docker context + ssh。

它当年解决什么

One command installed Docker on a cloud VM or VirtualBox host and generated TLS certs; eval $(docker-machine env host) switched targets. Before multi-host orchestration, that was the main way to manage remote Docker.

Bash
docker-machine create --driver virtualbox dev
eval $(docker-machine env dev)
docker ps
docker-machine ls

为什么不用了

  • 2019 年起官方不再维护,最后一个版本 0.16.2
  • 功能被 docker context 与各家云厂商的工具取代
  • Swarm 也不再是主流编排,Kubernetes 才是

现在的做法:context

Bash
docker context create remote --docker "host=ssh://deploy@10.0.0.5"
docker context use remote
docker ps                    # 实际跑在 10.0.0.5 上
docker context use default

ssh:// tunnels over SSH: no 2376 port, no certificate distribution — SSH access is enough.

对比

MachineContext
StatusDeprecatedSupported
TransportTCP + TLS certsSSH or TCP
SetupInstalls Docker for youHost must already have Docker
If scripts still call docker-machine env, docker context use is usually a one-line replacement.

Friends & Partners