How to push a dockerized project on heroku

限于喜欢 提交于 2021-01-29 08:20:53

问题


hope you are fine!

Actually, I have a dockerized rails API I'm working on.& I have to push it on Heroku.

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

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

rails aborted! NoMethodError: Cannot load database configuration: undefined method `[]' for nil:NilClass

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?


回答1:


When deploying a Docker container Heroku you need to follow a different method (currently you are just pushing the code git push heroku master).

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 

Second step: login into Heroku registry (only needed once)

heroku container:login

Third step: tag and push

# 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

See full reference at Heroku documentation



来源:https://stackoverflow.com/questions/64816892/how-to-push-a-dockerized-project-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!