Creating first docker container: Can't find host system file on build
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 <firstname.lastname@example.org> 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.
One Solution collect form web for “Creating first docker container: Can't find host system file on build”
Docker builds run on the docker host, not necessarily the client where you run the command, and so all the files needed to run the build are sent in the build context to the host. That context is most often the current directory, or
., that you pass at the end of the
docker build -t $image_name . command.
Everything that you try to include in the image with a
ADD is done in reference to that build context, not the filesystem on your client or host machine. So if you need a modules.conf, you’ll need to first copy that into your directory with the Dockerfile, and then
COPY the file from there.
As for why jekyll is looking for the file, I’m not familiar with jekyll, but it doesn’t look promising for something running inside of a container. The modules are kernel specific and containers are designed to be moved to different hosts with potentially different kernels.