<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anuj Upadhyay</title>
    <description>The latest articles on DEV Community by Anuj Upadhyay (@anuj97).</description>
    <link>https://dev.to/anuj97</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F454508%2F7279856f-d59d-43ab-b934-36652b906871.jpeg</url>
      <title>DEV Community: Anuj Upadhyay</title>
      <link>https://dev.to/anuj97</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anuj97"/>
    <language>en</language>
    <item>
      <title>Docker Images to Heroku</title>
      <dc:creator>Anuj Upadhyay</dc:creator>
      <pubDate>Mon, 21 Sep 2020 05:38:25 +0000</pubDate>
      <link>https://dev.to/anuj97/docker-images-to-heroku-4aln</link>
      <guid>https://dev.to/anuj97/docker-images-to-heroku-4aln</guid>
      <description>&lt;p&gt;Hey Devs,&lt;/p&gt;

&lt;p&gt;So I was wondering how to push my docker image to Heroku.&lt;br&gt;
Turns out it wasn't that hard.&lt;br&gt;
Below is a walk-through of what I did.&lt;/p&gt;

&lt;p&gt;So for the starters, I created an express app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir express-docker-up
cd express-docker-up
git init
npm init -y
npm install --save express
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Never forget the .gitignore file to keep the node_modules folder out of you git history. (If the your machine's node_modules get cloned to a different machine, errors may dial in)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/node_modules/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;add the index.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express')
const app = express()
const port = process.env.PORT

app.get('/', (req, res) =&amp;gt; res.send('Hello World!'))

app.listen(port, () =&amp;gt; console.log(`Example app listening on port ${port}!`))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create the Dockerfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:10-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY index.js .
CMD ["node", "index.js"]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create the heroku.yml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;build:
    docker:
      web: Dockerfile
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's start working on heroku now&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku login
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you don't have a pre-made app, create one&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku create
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Set the stack as container for the app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku stack:set container --app APP_NAME
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;now to commit and push&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Don't forget to give a meaningful commit message&lt;br&gt;
Check if heroku is present in your remote&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If not, make sure you have the heroku remote set&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote set heroku &amp;lt;heroku git repo(check your app settings on the web)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku git:remote --app APP_NAME
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And now push&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push heroku master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you wait, and when it's done, just go to the app url.&lt;br&gt;
Voila!&lt;/p&gt;

&lt;p&gt;I've uploaded this code to my &lt;a href="https://www.github.com/anuj97/express-docker-up"&gt;github&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
