本文介绍了将目录中的文件复制到与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-

我在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:

我通常会有一个用于构建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容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 04:04