问题
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