Great way to show off your app, with the idea that it always works on every OS. Well that the idea.
This article expect you to have Docker Hub account, and understand about NodeJS.
First you need to know what Node version your project running, you can’t pick the latest one without testing for errors. That why I save my node versions in my project, for example: node -v > .nvmrc.
My current node version on my project is: v14.4. And I’ll lookup Alpine with version 14.4: 14.4-alpine.
I only care Major and Minor versions. Luckily Node cares to dockerize their versions, it’s a good time to be alive, right? Before I had to install a could-be-working version for Alpine.
Took this from Nuxt .gitignore and convert to .dockerignore and made few changes, special for Docker
Add package.json run commands
- docker: The production mode running a node app. - docker-build: Build your app, then run Docker build command, when you save your docker app name to forget. - docker-run: Run docker container on your local machine port 8888. - docker-push: Build app and dockerize, then push to your Docker Hub.
Example running command
# Run docker container on your local machine port 8888
npm run docker-run
Run your node as 0.0.0.0
Make sure your node app runs host: 0.0.0.0 instead of host: localhost.