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

Pooria Sadeghy
  • 373
  • 1
  • 5
  • 17

1 Answers1

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.

Isa
  • 11
  • 5