npm install在dockerfile

时间:2017-01-22 19:28:39

标签: node.js npm dockerfile npm-install node-modules

我正在使用dockerfile来定义在前端使用React的自定义Wordpress发行版(通过特殊主题)。

为此,我正在修改官方Wordpress dockerfile并添加主题wgetnpm作为依赖项。

问题出在CUSTOM PART中的dockerfile的末尾。 npm install不会创建node_modules目录,但会成功完成(只是WARN消息)。然后npm start失败会产生错误,因为未安装rimrafwebpack npm包。

为什么/var/www/html/wp-content/themes/lexi-master/node_modules没有被创建?

错误:

sh: 1: rimraf: not found

npm ERR! Linux 4.4.20-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "clean"
npm ERR! node v7.4.0
npm ERR! npm  v4.1.1
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! Lexi-WP-Theme@0.0.1 clean: `rimraf dist`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the Lexi-WP-Theme@0.0.1 clean script 'rimraf dist'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the Lexi-WP-Theme package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     rimraf dist
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs Lexi-WP-Theme
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls Lexi-WP-Theme
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/html/wp-content/themes/lexi-master/npm-debug.log

npm ERR! Linux 4.4.20-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v7.4.0
npm ERR! npm  v4.1.1
npm ERR! code ELIFECYCLE
npm ERR! Lexi-WP-Theme@0.0.1 build: `npm run clean && webpack`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the Lexi-WP-Theme@0.0.1 build script 'npm run clean && webpack'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the Lexi-WP-Theme package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run clean && webpack
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs Lexi-WP-Theme
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls Lexi-WP-Theme
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/html/wp-content/themes/lexi-master/npm-debug.log

npm ERR! Linux 4.4.20-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "--prefix" "/var/www/html/wp-content/themes/lexi-master" "start"
npm ERR! node v7.4.0
npm ERR! npm  v4.1.1
npm ERR! code ELIFECYCLE
npm ERR! Lexi-WP-Theme@0.0.1 start: `npm run build && node server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the Lexi-WP-Theme@0.0.1 start script 'npm run build && node server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the Lexi-WP-Theme package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run build && node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs Lexi-WP-Theme
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls Lexi-WP-Theme
npm ERR! There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! Please include the following file with any support request:
npm ERR!     /var/www/html/npm-debug.log
The command '/bin/sh -c npm --prefix /var/www/html/wp-content/themes/lexi-master start' returned a non-zero code: 1

dockerfile中的可能原因(与npm install对齐):

  

RUN cd / var / www / html / wp-content / themes / lexi-master; npm install

...整个dockerfile(仅添加 CUSTOM PART ):

FROM php:7.1-apache

# install the PHP extensions we need
RUN set -ex; \
    \
    apt-get update; \
    apt-get install -y \
        libjpeg-dev \
        libpng12-dev \
    ; \
    rm -rf /var/lib/apt/lists/*; \
    \
    docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
    docker-php-ext-install gd mysqli opcache
# TODO consider removing the *-dev deps and only keeping the necessary lib* packages

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
        echo 'opcache.memory_consumption=128'; \
        echo 'opcache.interned_strings_buffer=8'; \
        echo 'opcache.max_accelerated_files=4000'; \
        echo 'opcache.revalidate_freq=2'; \
        echo 'opcache.fast_shutdown=1'; \
        echo 'opcache.enable_cli=1'; \
    } > /usr/local/etc/php/conf.d/opcache-recommended.ini

RUN a2enmod rewrite expires

VOLUME /var/www/html

ENV WORDPRESS_VERSION 4.7.1
ENV WORDPRESS_SHA1 8e56ba56c10a3f245c616b13e46bd996f63793d6

RUN set -ex; \
    curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
    echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
    tar -xzf wordpress.tar.gz -C /usr/src/; \
    rm wordpress.tar.gz; \
    chown -R www-data:www-data /usr/src/wordpress

COPY docker-entrypoint.sh /usr/local/bin/

# CUSTOM PART START

COPY lexi-master /var/www/html/wp-content/themes/lexi-master

# Install wget
RUN  apt-get update \
  && apt-get install -y wget \
  && rm -rf /var/lib/apt/lists/*

# Install dependencies
RUN apt-get update && apt-get install -y \
    software-properties-common
# RUN add-apt-repository universe
RUN apt-get update && apt-get install -y \
    apache2 \
    curl \
    git \
    libapache2-mod-php5 \
    php5 \
    php5-mcrypt \
    php5-mysql \
    python3.4 \
    python3-pip

# Install Node.js
RUN \
  cd /tmp && \
  wget http://nodejs.org/dist/node-latest.tar.gz && \
  tar xvzf node-latest.tar.gz && \
  rm -f node-latest.tar.gz && \
  cd node-v* && \
  ./configure && \
  CXX="g++ -Wno-unused-local-typedefs" make && \
  CXX="g++ -Wno-unused-local-typedefs" make install && \
  cd /tmp && \
  rm -rf /tmp/node-v* && \
  npm install -g npm && \
  printf '\n# Node.js\nexport PATH="node_modules/.bin:$PATH"' >> /root/.bashrc

RUN cd /var/www/html/wp-content/themes/lexi-master; npm install
RUN echo "export const WP_URL = '<http://www.example.com/wp-json/wp/v2';" > /var/www/html/wp-content/themes/lexi-master/src/wp-url.js

# Test the installation
RUN ls /var/www/html/wp-content/themes/lexi-master/
RUN ls /var/www/html/wp-content/themes/lexi-master/node_modules

# Start the server
RUN cd /var/www/html/wp-content/themes/lexi-master; npm start

# CUSTOM PART END

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]

/var/www/html/wp-content/themes/lexi-master/package.json

{
  "name": "Lexi-WP-Theme",
  "version": "0.0.1",
  "description": "",
  "license": "MIT",
  "dependencies": {
    "history": "^1.9.0",
    "isomorphic-fetch": "^2.1.1",
    "react": "^0.14.0-rc1",
    "react-dom": "^0.14.3",
    "react-redux": "^3.0.1",
    "react-router": "1.0.0-rc1",
    "redux": "^3.0.2",
    "redux-thunk": "^1.0.0"
  },
  "devDependencies": {
    "babel-core": "^5.6.18",
    "babel-loader": "^5.1.4",
    "css-loader": "^0.18.0",
    "debug": "^2.2.0",
    "extract-text-webpack-plugin": "^0.8.2",
    "file-loader": "^0.8.4",
    "html-webpack-plugin": "^1.6.1",
    "react-hot-loader": "^1.3.0",
    "rimraf": "^2.5.0",
    "style-loader": "^0.12.3",
    "webpack": "^1.9.11",
    "webpack-dev-server": "^1.9.0"
  },
  "scripts": {
    "clean": "rimraf dist",
    "build": "npm run clean && webpack",
    "start": "npm run build && node server.js"
  }
}

0 个答案:

没有答案