Need an advice to dockerize and run a node JS static-content app on K8s cluster.
I have a static web-content which I run "npm run build” into the terminal which generates /build and direct my IIS webserver to /build/Index.html.
Now, I started creating a Docker file, how do I point my nodeJS image to invoke /build/Index.html file
FROM node:carbon
WORKDIR /app
COPY /Core/* ./app
npm run build
EXPOSE 8080
CMD [ "node", ".app/build/index.html" ]
Please how can I run this app only on node v8.9.3 and npm 5.6.0 ?
Any inputs please ?
Assumptions:
package.json
is under Code
directory.npm run build
will be running outside of the container and a build
directory will be created in Code
directory.Code/build
directory under /app
directory of the container.package.json
to /app
folder and will run the website through scripts available in package.json
file.Solution:
I would say add a script
named start
in the package.json
and call that script from Dockerfile's CMD
command. The script would look like:
"scripts": {
"start": "node ./index.html",
},
And the Dockerfile
would look like:
FROM node:8.9.3
# Make app directory in the container.
RUN MKDIR /app
# Copy whole code to app directory.
COPY Code/build/ /app
# Copy package.json app directory.
COPY package.json /app
# make app directory as the working directory.
WORKDIR /app
# Install dependencies.
RUN npm install -only=production
# Expose the port
EXPOSE 8080
# Start the process
CMD ["npm", "start"]
You can specify the version of node specifically:
FROM node:8.9.3