问题
Currently, the DDEV web container does not come with nvm (node version manager). How can I add and use it via the DDEV config.yaml file?
回答1:
With the help of @greggles and @heddn on the #ddev Slack channel (on the Drupal Slack workspace), I got it working with the following post-start hook:
hooks:
post-start:
- exec: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
- exec: rm -f ../.nvmrc && export NVM_DIR="$HOME/.nvm" && source "$NVM_DIR/nvm.sh" && nvm install 8.11.1 && nvm use 8.11.1
This installs nvm then sets node to version 8.11.1
-mike
回答2:
Another potential solution would be to add it to the .ddev/web-build/Dockerfile
as the DDEV documentation suggests here: https://ddev.readthedocs.io/en/stable/users/extend/customizing-images/#adding-extra-dockerfiles-for-webimage-and-dbimage
回答3:
I recommend using the .ddev/web-build/Dockerfile approach, as it doesn't cost you every time you do a ddev start
; it just builds one time in each project (and when you upgrade ddev).
Place this file in .ddev/web-build/Dockerfile:
ARG BASE_IMAGE
FROM $BASE_IMAGE
ENV NVM_DIR=/usr/local/nvm
ENV NODE_DEFAULT_VERSION=v6.10.1
RUN curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh -o install_nvm.sh
RUN mkdir -p $NVM_DIR && bash install_nvm.sh
RUN echo "source $NVM_DIR/nvm.sh" >>/etc/profile
RUN bash -ic "nvm install $NODE_DEFAULT_VERSION && nvm use $NODE_DEFAULT_VERSION"
RUN chmod -R ugo+w $NVM_DIR
Change NODE_DEFAULT_VERSION to what you'd like it to be. You can add to this to use all the features of nvm; you could install more than one version, and use nvm use <otherversion>
in a post-start hook if you wanted to.
For more about how to use and install nvm, see the README.
For more about how to use ddev's add-on Dockerfile capability, see ddev docs on add-on Dockerfile
For details about Dockerfile syntax, see Docker's Dockerfile reference
来源:https://stackoverflow.com/questions/58415512/how-can-i-add-and-use-nvm-in-a-ddev-web-container