An instruction on how to deploy a node app to a server that is running dokku.
An instruction on how to deploy a node app to a server that is running dokku.
process.env.PORT
postinstall
hook in package.json
."dependency-name": "git+ssh://[email protected]:organization/repository.git#tag"
.NODE_ENV=production
by default. If you need a different environment for a specific task (e.g. npm run test
), specify it explicitly in the respective npm script (e.g. NODE_ENV=test npm run test
).git remote add dokku dokku@dokku-host:node-app
This repository contains an app that meets these requirements (but has no private dependencies).
First install dokku.
Then:
# Create the app
dokku apps:create node-app
# Set up a port mapping
dokku config:set node-app DOKKU_PROXY_PORT_MAP=http:80:5000
# Enable installing dev dependencies
dokku config:set node-app NPM_CONFIG_PRODUCTION=false
If the app has private dependencies e.g. from Bitbucket, setup ssh keys:
/home/dokku/.deployment-keys/shared/.ssh/id_rsa.pub
.dokku hostkeys:shared:autoadd bitbucket.org
.dokku
user and verify the app can be cloned and its dependencies installed. If there are issues, generate an ssh key manually and try again. After this, copy the key pair to .deployment-keys/shared/.ssh/
and the known_hosts
file to .hostkeys/shared/.ssh/
.After the app and the host is set up, you can deploy with git push dokku master
from the app directory on your local machine.
Parameters that are secret or affect Dokku behaviour should be applied via dokku config:set node-app ENV_PARAM_1=false
. These parameters are shared for all commands that are executed during the deploy (e.g. npm run build
and npm run start
).
Other env parameters should be applied in npm scripts so they are decoupled from the hosting (e.g. NODE_ENV=production npm start
).
dokku domains:add node-app www.domain.tld
A
record that points to the public IP of the server.dokku letsencrypt node-app
dokku letsencrypt:cron-job --add
so the certificate is renewed automatically.DOKKU_REMOTE_URL
.bitbucket-pipelines.yml
file from this repo.