-
Create a
Dockerfile
on the root of your project. For example, thisDockerfile-myaplication
:FROM evandrocoan/ubuntu18nodejspython:latest RUN npm install -g serve CMD ip address show && serve --single --no-clipboard --listen ${PORT} .
- This
Dockerfile-myaplication
file just launches a http server on the root directory of your docker machine. - The image
evandrocoan/ubuntu18nodejspython:latest
, is a simple image withUbuntu 18.04
and a few updates: https://hub.docker.com/repository/docker/evandrocoan/ubuntu18nodejspython - Heroku will define a random environment variable
PORT
, which yourweb
application should bind within 60 seconds after start: https://devcenter.heroku.com/articles/dynos#web-dynos - The
web
service will sleep once idle for some time and it will stop consuming your monthly 550 free dyno hours: https://devcenter.heroku.com/articles/free-dyno-hours - Any service other than
web
will not sleep and they will keep consuming your monthly free dynos 24/7. Use the commandheroku ps
to see your monthly free dyno hours.
- This
-
Create a minimal
heroku.yml
file on the root of your project. For example:build: docker: web: Dockerfile-myaplication
- The
build.docker.web**
item is a required item which must be named as**web
. It points out which one is theDockerfile
for Heroku to use. - The
web
service, is the only service which will be started automatically by Heroku. Any other service other thanweb
needs to be started manually with:heroku ps:scale otherservicename=1
- Heroku will use the
CMD
from yourDockerfile
, however, you can override theCMD
command by defining therun
section:... web: Dockerfile-myaplication run: web: bash -c 'serve --single --no-clipboard --listen ${PORT}'
- https://medium.com/tarkalabs/docker-deployments-to-heroku-5802b14df4fa
- The
-
git init
-
git add heroku.yml
-
git add Dockerfile-myaplication
-
git commit -m "My cool application"
-
You are done. This is all you need to run a docker container with Heroku. Now to publish it:
heroku login
heroku apps:create mycustomanduniquename --remote heroku-git-remote
- Note: Your app will be available on the URL: https://mycustomanduniquename.herokuapp.com
- This will add a new
git remote
to your repository calledheroku-git-remote
. You can use this remote directly from git to deploy a new version of your application.
git push heroku-git-remote custombranch:master
- This will push updates from the local branch
custombranch
to the Heroku remote branchmaster
. On each push to the Heroku remotemaster
branch, the docker container image will be rebuilt with the changes on the git branch. - Add
--force-with-lease
to forced push the branch to the remote, causing the docker container to be rebuild.
- This will push updates from the local branch
heroku stack:set container
- Set this app as docker container
- All environment variables are passed automatically by Heroku to your docker build commands.
- To set environment variables on your Heroku remote instance:
heroku config
(to list variables)heroku config:set REACT_APP_GITHUB_TOKEN=your_token_af2dcas343...
- https://devcenter.heroku.com/articles/config-vars
-
Managing you application after creation:
heroku ps
- To list your running Heroku processes
heroku logs --ps web
- To see the logs of you
web
Heroku running dyno (container)
- To see the logs of you
- To rename you application after creating it:
heroku apps:rename mynewuniquename
- It will automatically update you URL on: https://mynewuniquename.herokuapp.com
- To rename your Heroku git remote:
heroku git:remote -a [app-name] -r [new-remote-name]
git remote rm heroku-old-remote
- https://stackoverflow.com/questions/6226846/how-to-change-a-git-remote-on-heroku?answertab=votes#tab-top
The example commands are for the repository . To put this project online on Heroku, you are going to need:
heroku login
heroku apps:create evandrocoanreactbackend --remote heroku-backend
heroku apps:create evandrocoanreactfrontend --remote heroku-frontend
- Note: Your app will be available on the URL: https://evandrocoanreactbackend.herokuapp.com https://evandrocoanreactfrontend.herokuapp.com
heroku stack:set -a evandrocoanreactbackend container
heroku stack:set -a evandrocoanreactfrontend container
- Set this app as docker container
git push heroku-backend custombranch:master
git push heroku-frontend custombranch:master
- To push updates from the local branch
custombranch
to the Heroku remote branchmaster
. On each push to the Heroku remotemaster
branch, the docker container image will be rebuilt with the changes on the git branch. - Add
--force-with-lease
to forced push the branch to the remote, causing the docker container to be rebuild.
- To push updates from the local branch
heroku ps
- To list your running Heroku processes
- To see the logs of you
web
Heroku running dyno (container)heroku logs -a evandrocoanreactbackend --ps web
heroku logs -a evandrocoanreactfrontend --ps web
- To set environment variables on your Heroku remote instance: https://devcenter.heroku.com/articles/config-vars
- frontend:
heroku config -a evandrocoanreactfrontend
(to list variables)heroku config:set -a evandrocoanreactfrontend REACT_APP_GITHUB_RESEARCHER_BACKEND_IP=127.0.0.1
heroku config:set -a evandrocoanreactfrontend REACT_APP_GITHUB_RESEARCHER_BACKEND_PORT=0
- backend:
heroku config -a evandrocoanreactfrontend
(to list variables)heroku config:set -a evandrocoanreactfrontend REACT_APP_GITHUB_RESEARCHER_TOKEN=as546a654...
- frontend:
- https://levelup.gitconnected.com/deploying-go-react-to-heroku-using-docker-9844bf075228
- moby/moby#2838 - Cannot kill or detach a docker container using Ctrl-C or Ctrl-\
- https://create-react-app.dev/docs/adding-custom-environment-variables
- https://devcenter.heroku.com/articles/procfile
- https://devcenter.heroku.com/articles/dynos
- https://medium.com/inato/how-to-setup-heroku-with-yarn-workspaces-d8eac0db0256
- https://stackoverflow.com/questions/38440876/stand-up-select-services-with-docker-compose
- https://www.ostechnix.com/explaining-docker-volumes-with-examples/
- https://stackoverflow.com/questions/44848721/docker-compose-inside-docker-in-a-docker