0

I want to build a vue 2 app with docker, but got sh: vue-cli-service: not found error. For serve, I have another docker files and everything there is fine, but in build I got this error!

Dockerfile

# build stage
FROM node:14.18.0-alpine as build-stage
ENV NODE_ENV=production
WORKDIR /var/www/html/app
COPY package*.json ./
RUN npm install -g @vue/cli
RUN npm i

COPY . .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

docker-compose.yml

version: '3.7'
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:80"

command: docker-compose up -d

1 Answer 1

1

Are you using volumes for your app service in your docker-compose file?

I got a similar error on Vue.js 2 with Docker npm run serve was failing because the node_modules repository went missing in the Docker container. The root cause of it was that I am using bind mounts to allow code hot reload in my development environment, which made Docker overwrite the node_modules repository after running npm install -g @vue/cli, which explains that cli couldn't be found.

I solved this by using a volume for the node_modules repository, as explained by this answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.