如何将Docker-compose管理的Docker容器推送到Heroku? [英] How to push Docker containers managed by Docker-compose to Heroku?

查看:294
本文介绍了如何将Docker-compose管理的Docker容器推送到Heroku?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个经过本地测试且可以运行的Web应用程序,该应用程序包含4个Docker容器:Java MVC,NodeJS,Flask和MongoDB。我有4个Dockerfile,每个都有一个,我使用docker-compose.yml管理构建。

I currently have a locally tested and working web app that consists of 4 docker containers: Java MVC, NodeJS, Flask, and MongoDB. I have 4 Dockerfiles, one for each, and I manage the builds with docker-compose.yml.

但是,现在我想将代码推送到Heroku,并阅读 https://devcenter.heroku.com/articles/container-registry-and-runtime 。但是,如何在生产线上使用docker-compose似乎模棱两可。这就是在文档上所说的:

However, now I want to push my code to Heroku and I read the documentation at https://devcenter.heroku.com/articles/container-registry-and-runtime. However, it seems very ambigious about how to use docker-compose on the production line. This is what it says on the docs:

如果您创建了多容器应用程序,则可以使用Docker Compose定义您的本地开发环境。学习如何使用Docker Compose进行本地开发。

"If you’ve created a multi-container application you can use Docker Compose to define your local development environment. Learn how to use Docker Compose for local development."

有人可以指导我一些实际的代码,说明如何使用以下方法将项目推送到Heroku容器Heroku的CLI?

Can anyone guide me to some actual code of how I can push my project to the Heroku Container using Heroku's CLI?

推荐答案

更准确的heroku文档可在此处找到:
https://devcenter.heroku.com/articles/container-registry-and-runtime

The more accurate heroku documentation for what you are looking to do is here: https://devcenter.heroku.com/articles/container-registry-and-runtime

以上内容将引导您设置heroku容器插件并登录到注册表。您甚至可以在dockerfile中的以下行中将映像迁移到Dockerfile:

The above will walk you through setting up the heroku container plugin and logging into the registry. You can even migrate an image to a Dockerfile with the following line in your dockerfile:

FROM "<insert Dockerfile tag here>"

要轻松进行设置,您将使用不同的后缀来命名Dockerfile,例如Dockerfile.mongo, Dockerfile.node,Dockerfile.flask和Dockerfile.javamvc。后缀告诉heroku您的Web应用程序使用的dyno名称。当需要推送所有容器时,可以使用以下命令来执行此操作,只要它们都具有唯一的后缀,该命令将以递归方式构建所有dockerfile:

To easily set this up, you will name your Dockerfiles with different suffixes, such as Dockerfile.mongo, Dockerfile.node, Dockerfile.flask, and Dockerfile.javamvc. The suffix tells heroku the dyno name used for your web app. When you need to push all of your containers, you can do so with the following command, which will recursively build all dockerfiles as long as all of them have unique suffixes:

heroku container:push --recursive

因为Heroku没有读取docker-compose文件,任何环境变量设置/端口暴露情况/等都需要迁移到Dockerfile。另外,由于我找不到如何在Heroku上使用容器进行持久性存储/卷装载的方法,因此我建议为您的mongo数据库使用Heroku附加组件。

As Heroku doesn't read docker-compose files, any environment variable setup/port exposure/etc will need to be migrated to the Dockerfile. Also as I can't find how to do persistent storage/volume mounting with containers on Heroku, I would recommend using a Heroku add-on for your mongo database.

On Heroku,您将看到您的应用程序在每个Dockerfile中以一个dyno运行,每个dyno的名称作为每个Dockerfile的后缀。

On Heroku, you will see your app running as one dyno per Dockerfile, with each dyno's name as the suffix of each Dockerfile.

UPDATE:


  1. Travis提出了一个很好的观点。确保在Dockerfile中包含CMD语句,否则heroku会引发错误。

  2. Yesterdayeroku最近还向该过程添加了一个步骤,您需要运行 heroku容器:对于要更新的​​每个测功机,释放<您的测功机名称>

  1. Travis brings up a good point. Make sure to have a CMD statement in your Dockerfile, otherwise heroku will throw an error.
  2. Yesterdayeroku also recently added a step to the process, you will need to run heroku container:release <your dyno name> for each dyno that you want to update.

这篇关于如何将Docker-compose管理的Docker容器推送到Heroku?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆