首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grunt-cli在挂载docker卷时不起作用,如果没有挂载,则可以

grunt-cli在挂载docker卷时不起作用,如果没有挂载,则可以
EN

Stack Overflow用户
提问于 2015-06-30 23:26:10
回答 1查看 344关注 0票数 1

我使用下面的Dockerfile设置了一个angular开发环境(不要尝试构建它,除非您真的很热情,因为这需要一段时间)。

代码语言:javascript
复制
FROM ubuntu:14.04

# build environment
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "nodejs", "npm", "git"]
RUN ["ln", "-s", "/usr/bin/nodejs", "/usr/bin/node"]
RUN ["npm", "install", "-g", "yo"]
RUN ["npm", "install", "-g", "bower"]
RUN ["npm", "install", "-g", "grunt-cli"]

WORKDIR /home/angular
ADD ./package.json /home/angular/package.json
ADD ./bower.json /home/angular/bower.json
ADD ./dist /home/angular/dist

RUN ["npm", "install"]
RUN ["bower", "install", "--allow-root"]

# sass depedencies
ENV RUBY_MAJOR 2.2
ENV RUBY_VERSION 2.2.2
ENV RUBY_DOWNLOAD_SHA256 5ffc0f317e429e6b29d4a98ac521c3ce65481bfd22a8cf845fa02a7b113d9b44

# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN ["apt-get", "install", "-y", "curl"]
RUN apt-get update \
    && apt-get install -y autoconf bison libgdbm-dev ruby \
    && rm -rf /var/lib/apt/lists/* \
    && mkdir -p /usr/src/ruby \
    && curl -fSL -o ruby.tar.gz "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.gz" \
    && echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.gz" | sha256sum -c - \
    && tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1 \
    && rm ruby.tar.gz \
    && cd /usr/src/ruby \
    && autoconf \
    && ./configure --disable-install-doc \
    && make -j"$(nproc)" \
    && make install \
    && apt-get purge -y --auto-remove bison libgdbm-dev ruby \
    && rm -r /usr/src/ruby

# skip installing gem documentation
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"

# install things globally, for great justice
ENV GEM_HOME /usr/local/bundle
ENV PATH $GEM_HOME/bin:$PATH

ENV BUNDLER_VERSION 1.10.5

RUN gem install bundler --version "$BUNDLER_VERSION" \
    && bundle config --global path "$GEM_HOME" \
    && bundle config --global bin "$GEM_HOME/bin"

# don't create ".bundle" in all our apps
ENV BUNDLE_APP_CONFIG $GEM_HOME

RUN gem install compass

VOLUME ["/home/me/code/correspondence/client/dist"]

ADD ./ /home/angular

如果我用以下命令运行:

代码语言:javascript
复制
sudo docker run -it me/angular /bin/bash

我可以毫无问题地使用grunt build。由于我尚未将卷附加到dist,因此该构建对其他容器(如use服务器)没有用处。但是正在运行:

代码语言:javascript
复制
sudo docker run -itv /home/me/code/correspondence/client/dist:/home/angular me/angular /bin/bash

导致grunt build命令在容器中不再可用:

代码语言:javascript
复制
grunt-cli: The grunt command line interface. (v0.1.13)

Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:

http://gruntjs.com/getting-started

唯一的区别是增加了音量。增加音量是如何导致这种不同的行为的?

EN

回答 1

Stack Overflow用户

发布于 2015-07-01 04:20:30

我猜想这是因为你在映像中放置了一些文件到/home/angular,并且当你在相同的路径(/home/angular)挂载你的卷时,你的卷隐藏了原始文件。

引用自documentation

注意:如果容器镜像中已经存在路径/opt/webapp,则其内容将被主机上的/src/webapp内容替换,以保持与挂载的预期行为一致

尝试将卷装载到另一个目录,例如/home/angular/dist/client

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31142409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档