LastTribunal
LastTribunal

Reputation: 1

Dockerizing any Angular SPA app that runs in node

There are a lot of Angular 2+ templates (for example http://coreui.io/) that run fine in Node, simply by:

npm install
npm start

However, making them run in Docker container is a challenge. I tried the standard approach to creating dockerfile but this doesn't work

Should there be a simple way of dockerizing any app that runs on Node with?

What am I missing?

This is what my dockerfile looks like (generated by yo docker):

    FROM node:latest
    WORKDIR /src
    EXPOSE 4200
    ENTRYPOINT ["npm", "start"]
    COPY . /src
    RUN npm install

Upvotes: 0

Views: 183

Answers (1)

Derick Bailey
Derick Bailey

Reputation: 72888

first thing i would suggest, don't use node:latest. what version of node do you normally run? specify that version.

you probably need to create the /src folder

and you should also change ENTRYPOINT to CMD

FROM node:7.9
RUN mkdir /src
WORKDIR /src

# cache the node modules for faster re-builds
COPY ./package.json /src
RUN npm install

COPY . /src

EXPOSE 4200
CMD ["npm", "start"]

this should cover the most basic of node apps.


things do get complex quickly, though. if you need more info on building out a proper dockerfile, i have a full course on docker with nodejs: https://sub.watchmecode.net/guides/build-node-apps-in-docker/

Upvotes: 1

Related Questions