如何在Heroku上推送dockerized项目 [英] How to push a dockerized project on heroku
问题描述
希望你很好!
实际上,我有一个正在使用的dockerized rails API.我必须将其推到Heroku上.
Actually, I have a dockerized rails API I'm working on.& I have to push it on Heroku.
我将pg gem添加到我的生产环境中&将MySql gem移至开发环境
I add pg gem to my production environment & move MySql gem to the development environment
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'mocha'
gem 'webmock'
gem 'mysql2'
end
group :production do
gem 'pg', '1.2.3'
end
然后,我运行 docker-compose up --build
&将代码推送到git后,我运行 git push heroku<分支名称>
一切正常.但是当我运行 heroku运行rails db:migrate
时,我得到了一个错误
And after that, I run docker-compose up --build
& after pushing my code to git I run git push heroku <branch name>
everything works fine.
but when I run heroku run rails db:migrate
i got an error
铁轨中止了!NoMethodError:无法加载数据库配置:nil:NilClass的未定义方法"[]"
rails aborted! NoMethodError: Cannot load database configuration: undefined method `[]' for nil:NilClass
这是我第一次在Heroku上推送dockerized项目,我不知道该怎么做.有人可以指导我吗?
This is my first time to push a dockerized project on Heroku, I don't know how to do this. can anyone please guide me?
推荐答案
在部署Docker容器Heroku时,您需要采用其他方法(当前您只是在推送代码 git push heroku master
)
When deploying a Docker container Heroku you need to follow a different method (currently you are just pushing the code git push heroku master
).
第一步:在本地构建Docker映像并对其进行测试.
First step: build your Docker image locally and test it.
# build image
docker build -t com.example/myapp .
# run container using mapping port 8886 to 8886
docker run -it --name myapp -p 8886:8886 com.example/myapp
第二步:登录Heroku注册表(只需一次)
Second step: login into Heroku registry (only needed once)
heroku container:login
第三步:标记并推送
# tag to match Heroku naming template (this is example uses `web` Dyno)
docker tag com.example/myapp registry.heroku.com/myapp/web
docker push registry.heroku.com/myapp/web
最后一步:释放(也称为启动应用程序)
Final step: release (aka start the application)
heroku container:release web -a myapp
请参见 Heroku文档
这篇关于如何在Heroku上推送dockerized项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!