Come installare l'ultimo nodo all'interno di un contenitore finestra mobile


26

Come posso installare l'ultimo nodo all'interno di un contenitore docker ubuntu 15.10? apt-get install nodejsinstalla la versione 0.1 e nessun npm

Grazie


L'hai risolto? Per me installa npm v 3.10, impossibile ottenere 6+
— simPod

Risposte:


31

Ok capito,

# update 
apt-get update
# install curl 
apt-get install curl
# get install script and pass it to execute: 
curl -sL https://deb.nodesource.com/setup_4.x | bash
# and install node 
apt-get install nodejs
# confirm that it was successful 
node -v
# npm installs automatically 
npm -v

Utilizzare curl -sL https://deb.nodesource.com/setup_5.x | bashper il nodo 5.x

Sostituire 5con la versione del nodo desiderata, ad es. 8, 12, ecc.


12
Ho visto queste stesse istruzioni in tutto il web ma non riesco a farlo installare npm. Dopo aver eseguito apt-get -y install nodejs, l'esecuzione di un comando npm non funziona. Ricevo/bin/sh: 1: npm: not found
— Alex White il

Ho lo stesso problema.
— E infine il

Cosa succede se desidero avere la versione esatta come 8.9.4? Il comando precedente non riesce.
— Sourav Prem,

2
Vedere questo . Nella sezione README spiega come ottenere una versione diversa. Inoltre, 4 sta per essere esaurito, quindi non usare esattamente il comando sopra.
— Nathaniel Ford,

/bin/sh: apt-get: command not found /bin/sh: apk: command not foundutilizzandoFROM amazonlinux:1
— OZZIE il

14

Soluzione aggiornata a gennaio 2019:

FROM ubuntu:latest
USER root
WORKDIR /home/app
COPY ./package.json /home/app/package.json
RUN apt-get update
RUN apt-get -y install curl gnupg
RUN curl -sL https://deb.nodesource.com/setup_11.x  | bash -
RUN apt-get -y install nodejs
RUN npm install

ma in questo modo ottieni l'ultima versione 11 di nodejs. cosa succede se si desidera 11.5.4?
— Claudiu Creanga,

Dovrebbe avere le versioni secondarie in quel registro deb, basta sostituire la X con 5.4 (non testato dalla mia parte)
— Dan

Questa non è una buona pratica. Non lo eseguirai come root!
— Khalid,

10

Ecco come ho installato nodeJS in un contenitore. Nel mio caso, sto usando un'immagine di base nginx.

Utilizzare il seguente comando

    apt-get update -yq \
    && apt-get install curl gnupg -yq \
    && curl -sL https://deb.nodesource.com/setup_8.x | bash \
    && apt-get install nodejs -yq

GNUPG è necessario per l'installazione di nodeJS. Senza di essa, verrà visualizzato il seguente messaggio di errore;

[91mE: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation


2

installazione di nodejs v8 con l'immagine di base di Ubuntu 16.04:

FROM ubuntu:16.04

WORKDIR /app

RUN echo "LC_ALL=en_US.UTF-8" >> /etc/environment
RUN echo "LANG=en_US.UTF-8" >> /etc/environment
RUN echo "NODE_ENV=development" >> /etc/environment
RUN more "/etc/environment"
#RUN locale-gen en_US en_US.UTF-8
#RUN dpkg-reconfigure locales

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get dist-upgrade -y
RUN apt-get install curl htop git zip nano ncdu build-essential chrpath libssl-dev libxft-dev pkg-config glib2.0-dev libexpat1-dev gobject-introspection python-gi-dev apt-transport-https libgirepository1.0-dev libtiff5-dev libjpeg-turbo8-dev libgsf-1-dev fail2ban nginx -y

# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN apt-get install --yes nodejs
RUN node -v
RUN npm -v
RUN npm i -g nodemon
RUN nodemon -v

# Cleanup
RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y

Ho anche installato alcune dipendenze extra di cui ho bisogno in modo da poter ripulire questo codice per le tue esigenze. Ma installa nodejs & npm & nodemon.


1

Sto usando il seguente file Docker per installare la versione 8.10.0 del nodo.

Qui ho usato NVM (Node Version Manager) , quindi possiamo scegliere quale versione del nodo deve essere installata su quel contenitore. Utilizzare il percorso assoluto di npm durante l'installazione dei moduli del nodo (ad esempio: /root/.nvm/versions/node/v${NODE_VERSION}/bin/npm install leasot @ latest -g)

   FROM ubuntu:18.04
   ENV NODE_VERSION=8.10.0
   RUN apt-get update && \
       apt-get install wget curl ca-certificates rsync -y
   RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
   ENV NVM_DIR=/root/.nvm
   RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
   RUN . "$NVM_DIR/nvm.sh" &&  nvm use v${NODE_VERSION}
   RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
   RUN cp /root/.nvm/versions/node/v${NODE_VERSION}/bin/node /usr/bin/
   RUN cp /root/.nvm/versions/node/v${NODE_VERSION}/bin/npm /usr/bin/
   RUN /root/.nvm/versions/node/v${NODE_VERSION}/bin/npm install  leasot@latest -g

Nota: questo è un file Docker ritagliato.

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.