在码头处安装nvm [英] install nvm in docker

查看:208
本文介绍了在码头处安装nvm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个新的Docker映像,我正在寻找NVM安装,以便我可以管理nodejs。



阅读文档如何安装NVM,他们提到您需要源自您的.bashrc文件才能开始使用NVM。



我已经尝试将其设置在Dockerfile中,但到目前为止建筑物失败,出现错误:



bash:nvm:command not found



以下是相关的行从我的Docker文件:

 添加文件/ nvm_install.sh / root / 
运行chmod a + x / root / nvm_install .sh
RUN bash -c/root/nvm_install.sh
RUN bash -l -csource /root/.bashrc
RUN cd / root
RUN bash -l -cnvm install 0.10.31

这是尝试构建的输出: / p>

docker build -t nginx_dock。

 步骤0:FROM ubuntu 
---> 826544226fdc
步骤1:MAINTAINER dficociello
--->使用缓存
---> da3bc340fbb3
步骤2:运行apt-get update
--->使用缓存
---> 6b6b611feb4f
步骤3:运行apt-get install nginx curl -y
--->使用缓存
---> 159eb0b16d23
步骤4:运行触摸/root/.bashrc
--->使用缓存
---> 5e9e8216191b
步骤5:ADD文件/ nginx.conf / etc / nginx /
--->使用缓存
---> c4a4a11296a2
步骤6:ADD文件/ nvm_install.sh / root /
--->使用缓存
---> b37cba2a18ca
步骤7:运行chmod a + x /root/nvm_install.sh
--->使用缓存
---> bb13e2a2893d
步骤8:运行bash -c/root/nvm_install.sh
--->使用缓存
---> 149b49a8fc71
步骤9:运行bash -l -csource /root/.bashrc
--->运行在75f353ed0d53
---> 0eae8eae7874
删除中间容器75f353ed0d53
第10步:运行cd / root
--->运行在feacbd998dd0
---> 284293ef46b0
删除中间容器feacbd998dd0
第11步:运行bash -l -cnvm install 0.10.31
--->运行在388514d11067
bash:nvm:command not found
2014/09/17 13:15:11命令[/ bin / sh -c bash -l -cnvm install 0.10.31]返回一个非零代码:127

我对Docker很新,所以我可能会缺少一些东西编写Dockerfiles的基础,但到目前为止,我完成的所有阅读都没有给我一个很好的解决方案。



谢谢

解决方案

当您运行bash ... 每次在单独的进程中运行时,环境中设置的任何内容没有维护。以下是我如何安装 nvm

  #用bash替换shell,以便我们可以源文件
RUN rm / bin / sh&&& ln -s / bin / bash / bin / sh

#设置debconf以非交互方式运行
RUN echo'debconf debconf / frontend select Noninteractive'| debconf-set-choices

#安装基础依赖项
RUN apt-get update&& apt-get install -y -q --no-install-recommendations \
apt-transport-https \
build-essential \
ca-certificates \
curl \
git \
libssl-dev \
python \
rsync \
软件属性常见\
wget \\ \\
&&& rm -rf / var / lib / apt / lists / *

ENV NVM_DIR / usr / local / nvm
ENV NODE_VERSION 0.10.33

#安装nvm节点和npm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash \
&&来源$ NVM_DIR / nvm.sh \
&& nvm install $ NODE_VERSION \
&&& nvm别名默认$ NODE_VERSION \
&&& nvm使用默认

ENV NODE_PATH $ NVM_DIR / v $ NODE_VERSION / lib / node_modules
ENV PATH $ NVM_DIR / v $ NODE_VERSION / bin:$ PATH


I am in the process of building a new Docker image and I'm looking to get NVM installed so I can manage nodejs.

Reading the docs on how to install NVM they mention that you need to source your .bashrc file in order to start using NVM.

I've tried to set this up in a Dockerfile, but so far building fails with the error:

"bash: nvm: command not found"

Here are the relevant lines from my Dockerfile:

ADD files/nvm_install.sh /root/
RUN chmod a+x  /root/nvm_install.sh
RUN bash -c "/root/nvm_install.sh"
RUN bash -l -c "source /root/.bashrc"
RUN cd /root
RUN bash -l -c "nvm install 0.10.31"

Here is the output from trying to build:

docker build -t nginx_dock .

Step 0 : FROM ubuntu
---> 826544226fdc
Step 1 : MAINTAINER dficociello
---> Using cache
---> da3bc340fbb3
Step 2 : RUN apt-get update
---> Using cache
---> 6b6b611feb4f
Step 3 : RUN apt-get install nginx curl -y
---> Using cache
---> 159eb0b16d23
Step 4 : RUN touch /root/.bashrc
---> Using cache
---> 5e9e8216191b
Step 5 : ADD files/nginx.conf /etc/nginx/
---> Using cache
---> c4a4a11296a2
Step 6 : ADD files/nvm_install.sh /root/
---> Using cache
---> b37cba2a18ca
Step 7 : RUN chmod a+x  /root/nvm_install.sh
---> Using cache
---> bb13e2a2893d
Step 8 : RUN bash -c "/root/nvm_install.sh"
---> Using cache
---> 149b49a8fc71
Step 9 : RUN bash -l -c "source /root/.bashrc"
---> Running in 75f353ed0d53
---> 0eae8eae7874
Removing intermediate container 75f353ed0d53
Step 10 : RUN cd /root
---> Running in feacbd998dd0
---> 284293ef46b0
Removing intermediate container feacbd998dd0
Step 11 : RUN bash -l -c "nvm install 0.10.31"
---> Running in 388514d11067
bash: nvm: command not found
2014/09/17 13:15:11 The command [/bin/sh -c bash -l -c "nvm install 0.10.31"] returned a non-zero         code: 127

I'm pretty new to Docker so I may be missing something fundamental to writing Dockerfiles, but so far all the reading I've done hasn't shown me a good solution.

Thanks

解决方案

When you RUN bash... each time that runs in a separate process, anything set in the environment is not maintained. Here's how I install nvm:

# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections

# Install base dependencies
RUN apt-get update && apt-get install -y -q --no-install-recommends \
        apt-transport-https \
        build-essential \
        ca-certificates \
        curl \
        git \
        libssl-dev \
        python \
        rsync \
        software-properties-common \
        wget \
    && rm -rf /var/lib/apt/lists/*

ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 0.10.33

# Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash \
    && source $NVM_DIR/nvm.sh \
    && nvm install $NODE_VERSION \
    && nvm alias default $NODE_VERSION \
    && nvm use default

ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH      $NVM_DIR/v$NODE_VERSION/bin:$PATH

这篇关于在码头处安装nvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆