dockerfile - Podman 在复制时提示目录不存在

标签 dockerfile podman docker-copy

我被 Dockerfile 困住了:

[2/2] STEP 31/42: COPY /opt/SIMULATeQCD/src /simulateqcd/src
Error: error building at STEP "COPY /opt/SIMULATeQCD/src /simulateqcd/src": checking on sources under "/opt/SIMULATeQCD/podman-build": copier: stat: "/opt/SIMULATeQCD/src": no such file or directory

但是,它确实存在,所以我对 podman 正在寻找什么感到困惑:

[grant@simulateqcd podman-build]$ ls -al /opt/SIMULATeQCD/src
total 144
drwxr-xr-x. 12 grant grant  4096 Apr 14 16:23 .
drwxr-xr-x.  3 root  root     25 Apr 14 16:20 ..
-rw-r--r--.  1 grant grant 52854 Apr 14 16:09 CMakeLists.txt
-rwxr-xr-x.  1 grant grant   126 Apr 14 16:09 cmake.sh

我花了 45 分钟的大部分时间来处理上下文、检查权限、关闭 SELinux,并且不知道还需要检查什么。我已经在我能想到的所有地方都给了它绝对路径,但它仍然说该路径不存在。

任何地方的一切都由 1000:1000 拥有。上下文目录为/opt/SIMULATeQCD,Dockerfile 位于/opt/SIMULATeQCD/podman-build 中。我像这样运行 Dockerfile:

      podman build \
        --tag simulateqcd/simulateqcd:latest \
        --label name=simulateqcd \
        --build-arg CORES=${CORES} \
        --build-arg RHEL_VERSION=${RHEL_VERSION} \
        --build-arg CUDA_VERSION=${CUDA_VERSION} \
        --build-arg USERNAME=${USERNAME} \
        --build-arg GROUPNAME=${GROUPNAME} \
        --build-arg USER_ID=${USER_ID} \
        --build-arg GROUP_ID=${GROUP_ID} \
        --build-arg DIRECTORY=$topdir \
        -f $scriptdir/Dockerfile
        /opt/SIMULATeQCD

也许我还缺少其他东西吗?

更新

Dockerfile 是 here

COPY ./src /simulateqcd/src
COPY ./CMakeLists.txt /simulateqcd/CMakeLists.txt
COPY ./parameter /simulateqcd/parameter
COPY ./scripts /simulateqcd/scripts
COPY ./test_conf /simulateqcd/test_conf

脚本从 this line 运行

      podman build \
        --tag simulateqcd/simulateqcd:latest \
        --label name=simulateqcd \
        --build-arg CORES=${CORES} \
        --build-arg RHEL_VERSION=${RHEL_VERSION} \
        --build-arg CUDA_VERSION=${CUDA_VERSION} \
        --build-arg USERNAME=${USERNAME} \
        --build-arg GROUPNAME=${GROUPNAME} \
        --build-arg USER_ID=${USER_ID} \
        --build-arg GROUP_ID=${GROUP_ID} \
        --build-arg ARCHITECTURE=${ARCHITECTURE} \
        --build-arg USE_GPU_AWARE_MPI=${USE_GPU_AWARE_MPI} \
        --build-arg USE_GPU_P2P=${USE_GPU_P2P} \
        --build-arg TARGET=${TARGET} \
        -f $scriptdir/Dockerfile
        $topdir

其中 $topdir = /opt/SIMULATeQCD 和 $scriptdir=/opt/SIMULATeQCD/podman-buildsrc 位于 /opt/SIMUALTeQCD/src

运行./simulateqcd build可以得到:

Error: error building at STEP "COPY ./src /simulateqcd/src": checking on sources under "/opt/SIMULATeQCD/podman-build": copier: stat: "/src": no such file or directory
./simulate_qcd.sh: line 285: /opt/SIMULATeQCD: Is a directory

最佳答案

问题的两个相关方面是 Dockerfile 路径,可以通过 -f 选项和构建上下文提供,它是构建命令。

podman build 命令中设置上下文时,Dockerfile 内的所有后续 COPY 指令都相对于上下文路径。

假设您有以下目录结构:

.
├── opt
│   └── SIMULATeQCD
│       └── src
│           ├── CMakeLists.txt
│           └── cmake.sh
└── scripts
    └── Dockerfile

如果您像这样运行构建命令:

podman build -f scripts/Dockerfile -t alpine-context-so-img opt/SIMULATeQCD/src/

然后,Dockerfile 应该COPY 文件,就好像主机上的当前工作目录是 /opt/SIMULATeQCD/src:

FROM alpine:3.14
WORKDIR /target-path-in-container
# Next line is valid and also copies the two files
# COPY . . 
# But for better exemplification, I am copying each
# file verbosely:
COPY ./cmake.sh .
COPY ./CMakeLists.txt .
ENTRYPOINT [ "ls", "/target-path-in-container"]

现在,如果您运行容器,则应该在容器中找到这两个文件:

$ podman run alpine-context-so-img
CMakeLists.txt
cmake.sh

关于dockerfile - Podman 在复制时提示目录不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76019045/

相关文章:

Docker 在不同的端口上运行容器

docker - 如何在一个docker-compose文件中使用两个Dockerfile?

podman - 从容器内部访问主机

quarkus - 使用 WSL2 + Podman 使用 TestContainers 运行 Quarkus 测试

docker - 如何使用 Docker 文件将一层中的多个文件复制到不同的位置?

postgresql - 如何在应用程序停止后避免 docker 容器停止

ubuntu - apt-get 命令在 docker 容器中不起作用

ubuntu - 安装 Podman DNSname - 安装 : cannot stat 'bin/dnsname' : No such file or directory

Docker,复制镜像,错误 - 错误 : failed to solve: failed to compute cache key: failed to calculate checksum

kubernetes - 如何使用kubernetes将数据从一个容器cp到另一个容器