Vazid
Vazid

Reputation: 803

docker container unable to start with error: no such file or directory

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.

Upvotes: 0

Views: 1649

Answers (1)

BMitch
BMitch

Reputation: 263469

/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.

Upvotes: 1

Related Questions