'Have node_modules in host
I have a NuxtJS project (which obviously contains a node_modules directory) running on Docker.
The main subject is that I don't want to install npm on my host (dev) machine. I want my container to npm install itself, and get the node_modules into my dev machine, but I can't figure it out...
This is my docker-compose.yml:
version: '3.7'
services:
nuxtjs:
build:
context: .
dockerfile: docker/nuxtjs/Dockerfile
environment:
API_BASE_URL: ${API_BASE_URL}
ports:
- "8000:80"
container_name: ${NUXTJS_CONTAINER_NAME}
docker-compose.dev.yml (which is executed there on my dev machine)
version: '3.7'
services:
nuxtjs:
volumes:
- ./front:/usr/src/app
- /usr/src/app/node_modules
And the dockerfile:
FROM node:lts
# create destination directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# copy the app, note .dockerignore
COPY ./front /usr/src/app
RUN yarn
# build necessary, even if no static files are needed,
# since it builds the server as well
RUN yarn build
# expose 5000 on container
EXPOSE 80
# set app serving to permissive / assigned
ENV NUXT_HOST=0.0.0.0
# set app port
ENV NUXT_PORT=80
# start the app
CMD [ "yarn", "dev" ]
The node_modules directory is created, but nothing is installed into it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
