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.

Y0gesh Gupta
  • 2,184
  • 5
  • 40
  • 56

1 Answers1

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}"
Popmedic
  • 1,791
  • 1
  • 16
  • 21
  • More succinctly: anything that gets `COPY`d into a Docker image must be in the same directory tree as the `Dockerfile`. You cannot `COPY` from an arbitrary place on disk. – David Maze Jul 09 '18 at 22:31
  • 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... – Popmedic Jul 09 '18 at 22:55