Docker镜像在文件添加时失败

问题描述 投票:0回答:1

这是我的 Dockerfile:

FROM debian:latest

LABEL MAINTAINER DINESH

LABEL version="1.0"

LABEL description="First image with Dockerfile & DINESH."

RUN apt-get clean

RUN apt-get update

RUN apt-get install -qy git

RUN apt-get install -qy locales

RUN apt-get install -qy nano

RUN apt-get install -qy tmux

RUN apt-get install -qy wget

RUN apt-get install -qy python3

RUN apt-get install -qy python3-psycopg2

RUN apt-get install -qy python3-pystache

RUN apt-get install -qy python3-yaml

RUN apt-get -qy autoremove

# ** ERROR IS BELOW **
ADD .bashrc /root/.bashrc

ADD .profile /root/.profile

ADD app /app

RUN locale-gen C.UTF-8 && /usr/sbin/update-locale LANG=C.UTF-8

ENV PYTHONIOENCODING UTF-8

ENV PYTHONPATH /app/

当我运行这个命令时 docker build -t myimage .它给出的错误如下。

"Step 17/20 : ADD app /app
ADD failed: stat /var/lib/docker/tmp/docker-builder687980062/.bashrc: no such file or directory"

我给了上面给定路径的权限,但它没有解决。请让我知道我如何解决它。

docker docker-compose dockerfile docker-machine
1个回答
1
投票

首先请确保文件存在于正确的目录中。no such file or directory

请你不要用ADD,而是用COPY的方式,对我有用。

COPY .bashrc /root/ 
COPY .profile /root/

还可以使文件存在于源点和目的地。

另外,根据最佳实践,你可以合并行,并制作一个命令。

RUN apt-get update -yq \
    && apt-get install -y python3-dev build-essential -yq \
    && apt-get install curl -yq \
    && pip install -r requirements.txt \
    && apt-get purge -y --auto-remove gcc python3-dev build-essential

0
投票

改为。

ADD .bashrc /root/ 
ADD .profile /root/
ADD app /

从文件中:ADD src ... dest.

dest是一个绝对路径,或者相对于WORKDIR的路径,源文件将被复制到目标容器里面。

© www.soinside.com 2019 - 2024. All rights reserved.