2

I am trying to copy content of a directory while creating the docker image in the Dockerfile but while copying its giving me error-

COPY failed: stat /var/lib/docker/tmp/docker-builder108255131/Users/user_1/media : no such file or directory

I have the following file in the Dockerfile-

COPY /Users/user_1/media/. /code/project_media/ 

The media directory is in a seperate directory level then Dockerfile.

1 Answer 1

1

Sorry per dockerfile documentation:

Multiple resources may be specified but the paths of files and directories will be interpreted as relative to the source of the context of the build

https://docs.docker.com/engine/reference/builder/#copy

I usually will have a script for building the docker, and in that script will copy the files need for the COPY command into either the same directory or sub-directory of the "context of the build" (a very confusing way of saying the same directory as the dockerfile is in)

DOCKER_BUILD_DIR="./build/docker" DOCKERFILE="./docker/Dockerfile" MEDIA_FILES="/Users/user_1/media" mkdir -p "${DOCKER_BUILD_DIR}/${MEDIA_FILES}" cp -f "${DOCKERFILE}" "${DOCKER_BUILD_DIR}/" cp -rf "${MEDIA_FILES}" "${DOCKER_BUILD_DIR}/${MEDIA_FILES}/.." docker build "${DOCKER_BUILD_DIR}" 
Sign up to request clarification or add additional context in comments.

2 Comments

More succinctly: anything that gets COPYd into a Docker image must be in the same directory tree as the Dockerfile. You cannot COPY from an arbitrary place on disk.
The "Context of the Build" makes perfect sense if you look at the docker build command. The command is docker build [OPTIONS] PATH | URL | - where PATH | URL | - is your "Context of the Build." If you are just looking at the "Dockerfile" reference, then it is confusing to me...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.