Ubuntu: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04
OSX: https://store.docker.com/editions/community/docker-ce-desktop-mac
Ubuntu users create Dockerhub account at: https://hub.docker.com/ For Mac users, your Dockerhub credentials should have been created when you registered for Docker Store.
touch Dockerfile
in project root directory.
Add these contents to your Dockerfile:
# Built from Node from official Node base image
FROM node:10.0
# Specify an optional argument with a default value
ARG app_directory=/app
# Set the app directory as the context for all commands and entry to the container
WORKDIR ${app_directory}
# ONLY copy over the package.json to install NPM packages
COPY package.json .
# Install node module dependencies
RUN npm install
# Add the rest of the project files(most builds will start from here based on cache)
COPY . .
# Start the node application as you normally would
CMD ["node", "server.js"]
touch .dockerignore
Add these contents to your .dockerignore
file:
.git
.idea
**/node_modules
.DS_Store
.data
docker build -t <username>/<appname> .
docker images
to check your new image is in local registry
docker run -p 6969:6969 -d <username>/<appname>
Smoke test: curl localhost:8080
Associate local docker client to Docker Hub account: docker login --username=yourhubusername [email protected]
Push image to public registry on Docker Hub: docker push <username>/<appname>
Remember that these images are public! Meaning anybody can view them. Do not store sensitive information, secrets keys, etc!!!
Make sure docker is installed on EC2 instance
docker run -p 6969:8080 -d <username>/<appname>
Resources: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/