0

i create a docker image using the following Dockerfile

FROM java:8-jdk
ENV DOCKER_HOME /docker
ENV CRAWLER_HOME /docker/crawler
RUN groupadd crawler && useradd -g crawler crawler
RUN mkdir -p ${DOCKER_HOME}
RUN mkdir -p ${CRAWLER_HOME}
COPY ./ ${CRAWLER_HOME}
RUN ls -la ${CRAWLER_HOME}/*
RUN chown -R crawler:crawler ${DOCKER_HOME} && chmod -R 755 ${DOCKER_HOME}
WORKDIR $CRAWLER_HOME
ENTRYPOINT [ "/docker/crawler/docker/Entrypoint.sh" ]

when i run the image without -v option it works fine(docker run sampleimage:1.0). But when i run with -v it gives the follwing error

docker run -v ~/docker:/docker sampleimage:1.0 
docker: Error response from daemon: OCI runtime create failed: container_linux.go:367: 
starting container process caused: exec: "/docker/crawler/docker/Entrypoint.sh": stat 
/docker/crawler/docker/Entrypoint.sh: no such file or directory: unknown.
ERRO[0000] error waiting for container: context canceled   

while building the image i tried to list the file in CRAWLER_HOME and the Entrypoint.sh file is present. Unable to find out why it is throwing no such file or directory while running.

4
  • Does the file ~/docker/crawler/docker/Entrypoint.sh exist on your host? If so, what is the first line?
    – BMitch
    Commented Jul 11, 2021 at 17:23
  • Why are you mounting the volume? Any specific reason behind doing that?
    – Hisham
    Commented Jul 11, 2021 at 17:26
  • @BMitch ~/docker/crawler/docker/Entrypoint.sh is not present in the host but present in the image. contents of tile Entrypoint.sh #!/bin/sh set -x set -e set -- /docker/crawler/docker/start.sh "$@" exec "$@"
    – Vazid
    Commented Jul 11, 2021 at 17:29
  • @Hisham i want to presereve the logs locally in the host machine.
    – Vazid
    Commented Jul 11, 2021 at 17:30

1 Answer 1

1

/docker/crawler/docker/Entrypoint.sh is not present in the host but present in the image.

Mounting a volume using the same kernel methods that mounting a filesystem in Linux uses elsewhere. When you mount on top of a directory that has contents, those contents are not visible as long as the mount exists. All access to the directory goes to the mounted filesystem. That means you don't merge what's in the image with what's on the host, instead you will only see what's in the volume.

The semi-exception to this is with named volume mounts. In that case, the named mount gets initialized on first use with the contents of the image. Then going forward, that named mount acts the same, shadowing the contents of the image, thought it isn't as apparent since the files from the image were copied into the volume. Note that this initialization only happens when the named volume is empty/new and the container is created, and doesn't run on every use of the volume, so you won't pickup changes to the image on a later run automatically.

The standard advice is to separate your data from your application, place them in separate folders. Then mount a volume for the data, and include the application binaries/scripts in the image.

Not the answer you're looking for? Browse other questions tagged or ask your own question.