DEV Community

Discussion on: How to Dockerize a Docusaurus v2 application

Collapse
 
danroscigno profile image
Dan Roscigno

Hi Cindy,
Thanks for this. I made one change as I saw that the node_modules/.cache dir could not be created (I think docusaurus writes there) at runtime. Here is the change I made to the Dockerfile (add a chown on the homedir for node):

# We'll run the app as the `node` user, so put it in their home directory
WORKDIR /home/node/app
# Do the chown so that the node_modules/.cache can be updated
RUN chown -R node:node /home/node

# Copy the source code over
COPY --chown=node:node . /home/node/app/
Enter fullscreen mode Exit fullscreen mode
Collapse
 
schatzopoulos profile image
Serafeim Chatzopoulos

I get the following error in the last step:

unable to convert uid/gid chown string to host mapping: can't find uid for user node: no such user: node
Any ideas? thanks

Collapse
 
schatzopoulos profile image
Serafeim Chatzopoulos

I found that removing the "--chown=node:node" part of the last COPY command solves the issue.
But I wonder if it is going to cause other issues.

Thread Thread
 
cauldyclark15 profile image
Joselie Castaneda
FROM node:lts as base
ENV NPM_CONFIG_LOGLEVEL=warn
ENV NPM_CONFIG_COLOR=false
WORKDIR /app
COPY . ./
RUN yarn install
RUN yarn build

FROM nginx:stable-alpine
COPY nginx.conf /etc/nginx/conf.d/configfile.template
ENV PORT 3000
ENV HOST 0.0.0.0
WORKDIR /home/node/app
RUN sh -c "envsubst '\$PORT'  < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf"
COPY --from=base /app/build /usr/share/nginx/html
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]
Enter fullscreen mode Exit fullscreen mode

I simplified mine to just do production version and it worked.