Can’t properly install npm package globally in docker container

I have a vue project. I don’t want to keep my environments at my host, I prefer to deal with docker. So, why it is so damn stupidly tedious and hard to deal with node that way? So I created Dockerfile with node, docker-compose.yml and pre-installed a vue-cli project via hepler node:alpine container. Then I’m going to make working compose thing. But it’s not working! Because my global npm packages just not found. There’s nothing in google that helped me.

docker-compose.yml

version: '3'
services:
  app:
    build: .
    container_name: app
    ports:
      - "8080:8080"
    volumes:
      - "./:/app"

Dockerfile

FROM node:alpine

RUN npm install -g @vue/cli @vue/cli-service-global

WORKDIR /app/app

ENTRYPOINT ["vue-cli-service", "serve"]

(there’s another app inside /app it’s ok)

And the error:

[[email protected] vue]$ docker-compose up -d
Removing app
Recreating 801627fa0179_app ... error

ERROR: for 801627fa0179_app  Cannot start service app: OCI runtime create failed: container_linux.go:367: starting container process caused: exec: "vue-cli-service": executable file not found in $PATH: unknown

ERROR: for app  Cannot start service app: OCI runtime create failed: container_linux.go:367: starting container process caused: exec: "vue-cli-service": executable file not found in $PATH: unknown
ERROR: Encountered errors while bringing up the project.

Answer

The documentation seems to indicate that the binary is not installed into one of your typical locations (nominally /usr/local/bin). A quick fix is to add the install location to your PATH variable.

FROM node:alpine
  
RUN npm install -g @vue/cli @vue/cli-service-global

WORKDIR /app/app

ENV PATH="${PATH}:/usr/local/lib/node_modules/@vue/cli-service-global/node_modules/.bin"

ENTRYPOINT ["vue-cli-service", "serve"]