api - 如何在远程 ubuntu 服务器上部署 docker 容器?

标签 api ubuntu docker ubuntu-server

我已经在 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/

相关文章:

api - 如果我知道发件人和收件人邮政编码,如何获取 FedEx 和 UPS 区域编号?

javascript - 使用 Google Translate API 进行翻译时排除 HTML 标签

wordpress - MySQL 使用 Wordpress 时内存不足,我需要多少内存?

Rubygems 没有将/var/lib/gems/1.8/bin 添加到 $PATH?

amazon-web-services - AWS ECR,基于 ECS 的部署 : nginx: [emerg] host not found in upstream "app:9000" in/etc/nginx/conf. d/default.conf:2

docker - SSH进入Rhel中的Docker容器

meteor - 在 docker 上运行 meteor 应用程序 - 不在 localhost 中打开

python - 从 NBA API 收集特定球员信息

python - 将 Google Picasa API 与 Python 结合使用

qt - 使用特定 QT 版本运行二进制文件 - 不能混合不兼容的 Qt 库