No access permission error with npm global install on docker image

前端 未结 5 1832
小鲜肉
小鲜肉 2021-01-31 09:19

I\'m trying to build a docker image with a global install of firebase-tools and angular-cli. I\'m building the same image for two versions of node: 6.x (LTS bor

5条回答
  •  旧巷少年郎
    2021-01-31 09:34

    instead of forcing NPM's hand to install the package inside the container I bypassed this issue by mapping/referncing a host folder for the missing module this also prevents future headaches for when I replace the docker image with the latest version, I won't have to repeat the stages to reinstall the missing module inside the container:

    the steps i took:

    1. create an empty folder on the host environment (will be used as a target for the node js modules). call it node_modules

    2. when launching running the docker container use the --volume and --env switches

    -- volume to pass map the new host folder (from step 1) to a folder accessible inside docker

    --env to define/set an environment variable NPM_CONFIG_PREFIX from inside the docker to the /node_modules folder we created in step 1

    1. access the container using :

      sudo docker exec -i -t sh

    and go to the folder above the folder right above the local /node_modules folder (this not the folder we mapped to the environment variable, but rather the preexisting folder that came with the docker image)

    then run the command:

    > npm install -g 
    

    example

    > npm install -g request
    

    this will install the module in the host folder we've created. this module will also be accessible from both docker and host.

提交回复
热议问题