2017-06-15 50 views
1

运行我安装yarn,然后我想用接下来的Dockerfile来执行它:纱失败的Dockerfile

FROM ubuntu:trusty 
.... 
USER node 
RUN npm install -g yarn 
RUN ["/bin/bash", "-c","yarn install"] 

但它失败:

/bin/bash: yarn: command not found 
ERROR: Service 'falink-frontend4' failed to build: The command '/bin/bash -c yarn install' returned a non-zero code: 127 

我只是尝试使用下一个:

FROM ubuntu:trusty 
....  
USER node 
RUN npm install -g yarn 
RUN yarn install 

但它无法用:

/bin/sh: 1: yarn: not found 
ERROR: Service 'falink-frontend4' failed to build: The command '/bin/sh -c yarn install' returned a non-zero code: 127 

然后我连接到容器使用docker exec -it XXXXX /bin/bash,我运行yarn install它工作正常。当我在Docker容器内访问时,我使用node用户作为Dockerfile。

这是我entery Dockerfile:

FROM ubuntu:trusty 

# Create app directory 
RUN mkdir -p /usr/src/app 


#use mirrors for faster apt downloads no matter where the machine that builds the image is 
RUN echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty main restricted universe multiverse" > /etc/apt/sources.list; \ 
    echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list; \ 
    echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list; \ 
    echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-security main restricted universe multiverse" >> /etc/apt/sources.list 

#install required software before using nvm/node/npm/bower 
RUN apt-get update && apt-get install -y libfreetype6 libfontconfig curl git python build-essential 

#add user node and use it to install node/npm and run the app 
RUN useradd --home /home/node -m -U -s /bin/bash node 

#allow some limited sudo commands for user `node` 
RUN echo 'Defaults !requiretty' >> /etc/sudoers; \ 
    echo 'node ALL= NOPASSWD: /usr/sbin/dpkg-reconfigure -f noninteractive tzdata, /usr/bin/tee /etc/timezone, /bin/chown -R node\:node /myapp' >> /etc/sudoers; 

#run all of the following commands as user node from now on 
USER node 

RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash 

#change it to your required node version 
ENV NODE_VERSION 6.11.0 

#needed by nvm install 
ENV NVM_DIR /home/node/.nvm 

#install the specified node version and set it as the default one, install the global npm packages 
RUN . ~/.nvm/nvm.sh && nvm install $NODE_VERSION && nvm alias default $NODE_VERSION && npm install -g yarn && npm install -g [email protected] [email protected] [email protected] [email protected] koa-route koa-connect-history-api-fallback koa-body-parser [email protected] axios lodash moment 

ADD ./Falink_front/run_all.sh /run_all.sh 

COPY ./Falink_front/webapp /myapp 

ADD ./Falink_front/scrapping.js /code/scrapping.js 
ADD ./Falink_front/package.json /code/package.json 
COPY ./Falink_front/public /code/public 
COPY ./Falink_front/src /code/src 
ADD ./Falink_front/yarn.lock /code/yarn.lock 

USER root 
RUN chown -R node:node /code 

USER node 
RUN ["/bin/bash", "-c","yarn install"] 

可能是什么问题呢?

回答

2

如果你仍然需要调整ubuntu:trusty图片,这个Dockerfile,灵感来自官方docker hub node:latest有一个功能yarn工作。

FROM ubuntu:trusty 

# Create app directory 
RUN mkdir -p /usr/src/app 

#use mirrors for faster apt downloads no matter where the machine that builds the image is 
RUN echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty main restricted universe multiverse" > /etc/apt/sources.list; \ 
    echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list; \ 
    echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list; \ 
    echo "deb mirror://mirrors.ubuntu.com/mirrors.txt trusty-security main restricted universe multiverse" >> /etc/apt/sources.list 

#install required software before using nvm/node/npm/bower 
RUN apt-get update && apt-get install -y libfreetype6 libfontconfig curl git python build-essential 

#allow some limited sudo commands for user `node` 
RUN echo 'Defaults !requiretty' >> /etc/sudoers; \ 
    echo 'node ALL= NOPASSWD: /usr/sbin/dpkg-reconfigure -f noninteractive tzdata, /usr/bin/tee /etc/timezone, /bin/chown -R node\:node /myapp' >> /etc/sudoers; 

RUN groupadd --gid 1000 node \ 
    && useradd --uid 1000 --gid node --shell /bin/bash --create-home node 

# gpg keys listed at https://github.com/nodejs/node#release-team 
RUN set -ex \ 
    && for key in \ 
    9554F04D7259F04124DE6B476D5A82AC7E37093B \ 
    94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ 
    FD3A5288F042B6850C66B31F09FE44734EB7990E \ 
    71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ 
    DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ 
    B9AE9905FFD7803F25714661B63B535A4C206CA9 \ 
    C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ 
    56730D5401028683275BD23C23EFEFE93C4CFFFE \ 
    ; do \ 
    gpg --keyserver pgp.mit.edu --recv-keys "$key" || \ 
    gpg --keyserver keyserver.pgp.com --recv-keys "$key" || \ 
    gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" ; \ 
    done 

#change it to your required node version 
ENV NPM_CONFIG_LOGLEVEL info 
ENV NODE_VERSION 6.11.0 

RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \ 
    && curl -SLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ 
    && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \ 
    && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ 
    && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \ 
    && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \ 
    && ln -s /usr/local/bin/node /usr/local/bin/nodejs 

ENV YARN_VERSION 0.24.6 

RUN set -ex \ 
    && for key in \ 
    6A010C5166006599AA17F08146C2130DFD2497F5 \ 
    ; do \ 
    gpg --keyserver pgp.mit.edu --recv-keys "$key" || \ 
    gpg --keyserver keyserver.pgp.com --recv-keys "$key" || \ 
    gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" ; \ 
    done \ 
    && curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \ 
    && curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \ 
    && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \ 
    && mkdir -p /opt/yarn \ 
    && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/yarn --strip-components=1 \ 
    && ln -s /opt/yarn/bin/yarn /usr/local/bin/yarn \ 
    && ln -s /opt/yarn/bin/yarn /usr/local/bin/yarnpkg \ 
    && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz 

# COPY YOUR APPLICATION'S FILES HERE and CHOWN 

USER node 
RUN yarn --help 

我会在构建结束看到yarn --verion输出:

Step 14/14 : RUN yarn --version 
---> Running in 9e7d8b42cd87 
0.24.6 
+0

真的感谢!最后,我使用“节点”泊坞窗图像,但它解决了我的问题!:) –

相关问题