简体   繁体   中英

Angular CLI Docker Development Env

I would like to create a docker image that helps me with my Angular CLI app development. I don't want to have to install node or npm on the machine I am developing on, I just want docker to be installed. I would like to run a docker image the gives me a bash terminal where I can run npm install , ng gc MyNewComponent , npm install New3rdPartyLib & ng serve etc.

I have made some reasonable progress. So far I have the dockerfile.

FROM ubuntu:19.10

WORKDIR /ui

RUN apt-get update -yq
RUN apt-get upgrade -yq

RUN apt-get install curl -yq
RUN curl --silent --location https://deb.nodesource.com/setup_13.x | bash -
RUN apt-get install nodejs -yq
RUN apt-get install git -yq

RUN npm install -g npm
RUN npm install -g @angular/cli

ENTRYPOINT /bin/bash

This I build to an image called ag-dev-env and fire it up with

docker run --rm -it -v $PWD:/ui -w /ui -p 4200:4200 -u root ag-dev-env /bin/bash

This is perfect, I am able run ng commands and some npm commands

My main issue is I cannot run npm install as there is some issue with the directory permissions. I get the following errors.

npm WARN tar ENOENT: no such file or directory, open '/ui/node_modules/.staging/rxjs-b34353e6/operators/pluck.js.map'

and

npm ERR! Command failed: git clone --depth=1 -q -b fix-redirects git://github.com/timaschew/cogent.git /root/.npm/_cacache/tmp/git-clone-2b29f5f2
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-2b29f5f2': Permission denied
npm ERR! 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-12-23T14_36_16_225Z-debug.log

I have done a lot of googling and am getting no where :(

You need to configure a different path for the cache. The default is the home directory of the current user. Which in your case is /root/.npm

npm config set cache /var/something --global 

I would recommend that you point the cache to a mounted directory on the host machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM