Creating first docker container: Can't find host system file on build

时间:2017-04-06 17:05:40

标签: docker

I'm trying to bundle my Jekyll blog as a docker container.

I found this Dockerfile which seems to suit my use case but wanted to be more hands on so I copied it directly into my repo:

FROM ruby:latest
MAINTAINER Peter Etelej <peter@etelej.com>

RUN apt-get -qq update && \
  apt-get -qq install nodejs -y && \
  gem install -q bundler

RUN mkdir -p /etc/jekyll && \
  printf 'source "https://rubygems.org"\ngem "github-pages"\ngem "execjs"\ngem "rouge"' > /etc/jekyll/Gemfile && \
  printf "\nBuilding required Ruby gems. Please wait..." && \
  bundle install --gemfile /etc/jekyll/Gemfile --clean --quiet

RUN apt-get clean && \
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV BUNDLE_GEMFILE /etc/jekyll/Gemfile

EXPOSE 4000

ENTRYPOINT ["bundle", "exec"]

CMD ["jekyll", "serve","--host=0.0.0.0"]

When I run it I get an error

jekyll 3.4.3 | Error: No such file or directory @ rb_sysopen - /etc/modules-load.d/modules.conf

The host system has this file but my assumption was that the container didn't have access to it so I tried to add it into the Dockerfile

ADD /etc/modules-load.d/modules.conf /etc/modules-load.d/modules.conf

I then docker build and get the error

lstat etc/modules-load.d/: no such file or directory

I don't understand why the container is looking for this file in the first place but I'm even more confused by the fact that I can't add a file which is clearly there.

1 个答案:

答案 0 :(得分:1)

Docker构建在docker主机上运行,​​不一定是运行命令的客户端,因此运行构建所需的所有文件都在构建上下文中发送到主机。该上下文通常是您在.命令末尾传递的当前目录或docker build -t $image_name .

您尝试在COPYADD的图像中包含的所有内容都是在引用该构建上下文时完成的,而不是客户端或主机上的文件系统。因此,如果您需要modules.conf,您需要首先使用Dockerfile将其复制到您的目录中,然后从COPY将文件复制到您的目录中。

至于为什么jekyll正在寻找文件,我对jekyll并不熟悉,但对于在容器内部运行的东西看起来并不乐观。这些模块是特定于内核的,容器被设计为移动到具有可能不同内核的不同主机。

相关问题