Codementor Events

How To Deploy A Minimal Docker App To Heroku

Published Feb 03, 2020
How To Deploy A Minimal Docker App To Heroku

Docker is a build and container management tool used by software development teams to develop/build, manage and ship their products faster and more efficiently to their users.

Learning how to use Docker in development is not the only way to leverage this tool, using this tool to run deployment to a cloud platform (of your choice) would be another way for you to upgrade your Docker skill.

Because of this, I would be showing and discussing how to build your Docker application using a Dockerfile and then ship it out to Heroku through the terminal.

Prerequisites

  • Working knowledge of how Docker and Dockerfiles work
  • A Heroku account, you can signup here if you don’t have an account to work with
  • A dockerhub account, you can open an account here
  • GitHub repo with the source code https://github.com/iidrees/deploy-docker-heroku

Step 1: Clone the repo https://github.com/iidrees/deploy-docker-heroku
Step 2: change into the deploy-docker-heroku project directory with the commanddeploy-docker-heroku
Step 3: In the project directory, run the command ls in the terminal and you should see different files and directories mirroring the screenshot below.

1*UPIyY2Bf8MYCBaQNjQQppQ.png

Step 4: In the docker/ directory, you should see a Dockerfile file where the below config for building a minimal image can be found.

Screenshot 2020-01-31 at 7.58.47 PM.png

Step 5: Please run the commanddocker build -t test-image -f docker/Dockerfile . in order to build the docker image for our Heroku deployment, see the screenshot below.

1*QA4GLJIrCIg-8TIef226Ig.png

Step 6: After the image is built, we would need to login into our Heroku account with the Heroku login , you should get the response Login in as <your_email_address> .

1*bc3DqUWkDKYZfU1WyTxiBA.png

Step 7: Next step is to create your Heroku App where the docker image would b deployed with the command heroku create <name_of_your_app> , if the command was successful a response similar to what is present in the screenshot below would be returned by that command.

1*S8MSpfKfFBdloADqXzBtOw.png

Step 8: After creating your Heroku App, you would then need to login to Docker using your Heroku token credentials so you would be able to push your image to the Heroku Docker Registry .
So you use the command below to login
docker login --username=<email_add_used_to_signup_to_heroku> password=$(heroku auth:token) registry.heroku.com
You should get a Login Succeeded response on your terminal

Step 9: After the Heroku Docker Registry login, you would need to push the Docker image you built in step 5 above.
But before we do that, we would need to login to the Heroku container Registry and also re-tagging the image we built above from test-image to registry.heroku.com/<heroku_app_name>/web by running the following commands:

  • heroku container:login which will return Login Succeeded
  • docker tag test-image registry.heroku.com/<name_of_your_app>/web after running the command to re-tag the image, run the command docker images in order to confirm that you have an image with the tag you have used.

Step 10: In this step, we would be pushing out docker image to the Heroku container registry, this is because, by design, that is the only way you would be able to deploy your docker app on Heroku.
In order to push your Heroku, remember that we have tagged the docker image with a name that has the registry.heroku.com URL or domain name, this would make it easier to point docker to the registry where the image should be pushed. In the case where the docker image is not tagged like this, then the image would be pushed to Dockerhub by default.

Step 11: After the image has been pushed to registry.heroku.com the Heroku docker registry, the final stage is to release in the image, in the Heroku app, we created above with the command heroku container:release web -a <name_of_web_app> .
After running the command you should see the response Releasing images to <name_of_web_app>... done displayed on your terminal.

After releasing the docker image and container in the Heroku application we created through the command line in Step 7, you should be able to access the application using this URL https://<name_of_your_app>.herokuapp.com . In the browser, you should see Hello World! returned in the browser.

The steps above are just some of the basic steps you can follow to deploy any Docker application to Heroku, but make sure that you have your Dockerfile written and ready.

HAPPY DEPLOYING!

Discover and read more posts from Idrees Ibraheem
get started
post commentsBe the first to share your opinion
Show more replies