将目录中的文件复制到与Dockerfile不在同一级别的Docker容器中 [英] Copying files in a directory to a docker container not at same level as Dockerfile

查看:559
本文介绍了将目录中的文件复制到与Dockerfile不在同一级别的Docker容器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Dockerfile中创建Docker映像时复制目录的内容,但是在复制它给我带来错误时-

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失败:stat
/ var / lib / docker / tmp / docker-builder108255131 / Users / user_1 / media:否
这样的文件或目录

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

我在Dockerfile中有以下文件-

I have the following file in the Dockerfile-

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

媒体目录位于单独的目录级别,然后是Dockerfile。

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

推荐答案

对不起,每个dockerfile文档:

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

我通常会有一个用于构建docker的脚本,并在该脚本中复制 COPY 将命令输入到构建上下文的相同目录或子目录中(说出与dockerfile相同的目录非常混乱的方式)

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}"

这篇关于将目录中的文件复制到与Dockerfile不在同一级别的Docker容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆