sh: 1: nuxt: not found
I'm always getting this error when trying to run the docker container.
It's only working when I have node modules and a .nuxt folder mounted from my local. As soon as I delete them, that docker container starts giving the same error.
Here is my dockerfile:
FROM node:16.14
WORKDIR /app
ADD package.json ./
RUN npm install
ADD . .
Here is my docker-compose.yml:
version: "3.9"
services:
web:
build: .
restart: always
container_name: myapp-nuxt
volumes:
- ".:/app"
depends_on:
- "server"
environment:
- NUXT_HOST=0.0.0.0
- NUXT_PORT=3001
network_mode: "host"
command: npm run dev
PS - I tried following almost all tutorials. Issue is same with all of them.
CodePudding user response:
The volumes:
block hides absolutely everything that the Dockerfile does and overwrites it with different content from your host. More specifically, it hides the node_modules
directory generated by RUN npm install
and replaces it with whatever might happen to be on the host in that directory. You don't need this volumes:
block and you can remove it.
# volumes: <-- remove this block:
# - ".:/app" <-- don't overwrite the application code in the image
(Also consider removing the unnecessary container_name:
option, moving the fixed environment:
and command:
settings into your Dockerfile, and not disabling Docker networking with network_mode: host
. You can probably get the Compose definition down to just the build:
line, the restart:
policy, declaring depends_on:
, and publishing ports:
.)