我已经在 docker 容器中实现了一个 API,我想将此容器部署到远程 ubuntu 服务器。我该怎么做呢? 我的 API 使用了很多资源,并且我使用了 MLDB 框架来实现它。我想在这个远程 ubuntu 服务器上部署包含 API 的容器。 到目前为止,我已经找到了许多在 AWS 和 DigitalOcean 上部署 API 的指南,但是由于我已经可以访问远程 ubuntu 服务器而不是不需要这些,对吗? 那么如何部署我的容器以便其他人能够测试我的 API?如果有更好的方法来部署我的 API(希望是免费的或廉价的),请告诉我。
提前致谢。
最佳答案
自从 Docker 18.09.0 发布以来这变得容易多了。此版本添加了对 ssh
协议(protocol)的支持到 DOCKER_HOST
环境变量和 -H
参数到 docker ...
命令。
首先,您需要 SSH access to the target machine (您可能需要任何方法)。
然后,要么:
# Re-direct to remote environment.
export DOCKER_HOST="ssh://my-user@remote-host"
# Run a container. To prove that we are on remote-host, this will print its hostname.
docker run --rm --net host busybox hostname -f
# All docker commands here will be run on remote-host.
# Switch back to your local environment.
unset DOCKER_HOST
或者,如果您愿意,只需一个命令即可完成所有操作:
docker -H "ssh://my-user@remote-host" run --rm --net host busybox hostname -f
请注意,docker-compose
v.1.23.1(截至撰写时的最新版本)及以下版本尚不支持此功能。但是,it will be part of the next release .
关于api - 如何在远程 ubuntu 服务器上部署 docker 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43505196/