簡體   English   中英

使用Dockerfile在ubuntu映像中安裝特定版本的node.js和npm

[英]Installing specific version of node.js and npm in ubuntu image with Dockerfile

我想知道如何更新我的自定義Dockerfile以安裝Node v6.3.1和NPM v3.10.6而不破壞其中的內容。

目前這是我的自定義文件:

FROM         ubuntu:16.10

MAINTAINER   Fátima Alves

COPY         . /my-software
WORKDIR        /my-software

RUN          apt-get update          \
                                  && \
             apt-get install -y      \
               python-dev            \
             tesseract-ocr

謝謝!


更新

目前我的dockerfile是這樣的:

FROM         ubuntu:16.10

MAINTAINER   Fátima Alves

COPY         ./dist            /my-software
COPY         ./s3-config.json  /my-software
COPY         ./_*              /my-software
COPY         ./node_modules    /my-software
WORKDIR                        /dataextractor

RUN          apt-get update          \
                                  && \
             apt-get install -y      \
             curl

RUN         curl -sL https://deb.nodesource.com/setup_6.x | bash - \
            && apt-get install -y nodejs

並且正在回歸:

The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_6.x | bash -             && apt-get install -y nodejs' returned a non-zero code: 1

也許我錯過了什么?

您可以按照常用的Ubuntu安裝說明,就在DockerfileRUN語句中

RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \
    && apt-get install -y nodejs

文件

為什么

因為https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions建議做“curl pipe bash”反模式,讓我們試着讓它變得更干凈。

什么

由於容器是由最終的操作系統和版本構建的,因此我們不需要該bash腳本的通用性。

怎么樣

如果我們仔細研究一下, https://deb.nodesource.com/setup_6.x我們發現它確實只為Debian做了兩件事

  1. 通過apt-key add 他們的公鑰添加到apt的keychain中
  2. 將他們的deb repo添加到新創建的文件/etc/apt/sources.list.d/nodesource.list

添加來源

我們能做的第二件事很容易。 這只是將它放在你的Dockerfile中:

COPY nodesource.list  /etc/apt/sources.list.d/nodesource.list

當然,您需要創建包含以下內容的nodesource.list

deb     https://deb.nodesource.com/node_6.x trusty main
deb-src https://deb.nodesource.com/node_6.x trusty main

添加可信密鑰

對於新的“干凈利落”, 第一件事情有點棘手。 我寧願在/etc/apt/trusted.gpg.d/添加一個keychain文件,而不是修改現有的/etc/apt/trusted.gpg文件(這就是apt-key add會做什么)。

他們在URL https://deb.nodesource.com/gpgkey/nodesource.gpg.key上的內容是公鑰,而不是鑰匙串。 要獲得一個鑰匙串文件,我們可以管它[不是apt-key ,而不是]如下:

curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | \
gpg --import --no-default-keyring --keyring ./nodesource.gpg

這創建了nodesource.gpg ,我們可以通過將它放在你的Dockerfile中來利用它:

COPY nodesource.gpg   /etc/apt/trusted.gpg.d/nodesource.gpg

像往常一樣安裝

瘋狂的間距和\\終止線是我使用的,因為我傾向於有很多額外的包安裝。

# Install software packages
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq && apt-get clean
RUN apt-get install -qqy \
                         nodejs \
    && \
    apt-get clean

你可以在https://gist.github.com/RichardBronosky/f748563dc328b12b39cd864973fcb138#file-dockerfile上看到完整的Dockerfile。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM