【问题标题】:Files not present in container after COPY or ADD in Dockerfile在 Dockerfile 中复制或添加后容器中不存在文件
【发布时间】:2021-05-04 14:29:56
【问题描述】:

我正在尝试构建一个简单的 docker 文件,该文件本身将启动一个组合队列。它可能会破坏容器的用途;但我发现这是我认为最适合我的情况。

尝试将文件复制到映像时,它不会失败,但运行后我找不到文件。我尝试了 ADD 和 COPY 指令。如下例所示,docker-compose.yml 和我的所有配置文件在启动后都不存在于容器中。有人可以帮忙吗?

这是我的 Dockerfile 以及它在映像构建和容器启动期间生成的日志

FROM docker/compose

# Default user defined values
ENV TIMEZONE=Europe/Paris
ENV PLAXDMIN_DNS="plaxdmin.default.org"

# Final values
ENV PLAXDMIN_VERSION="PL_V_PLACEHOLDER"


# Init folders and copy docker-compose api configuration files
WORKDIR /var/log/plaxdmin

WORKDIR /etc/plaxdmin
ADD ./resources/conf/* ./
RUN ls -al ./

WORKDIR /opt/plaxdmin/
ADD ./resources/docker-compose.yml ./
RUN ls -al ./

# Expose folders and port
EXPOSE 80

# On run debug and start compose fleet
CMD  docker -v \
    && docker-compose -v \
    && printenv \
    && ls -al /etc/plaxdmin \
    &&  ls -al /opt/plaxdmin/ \
    &&  ls -al /var/log/plaxdmin/ \
    && pwd \
    && whoami \
    && docker-compose up

plaxdmin_1   | Docker version 19.03.8, build afacb8b7f0
plaxdmin_1   | docker-compose version 1.26.2, build eefe0d3
plaxdmin_1   | HOSTNAME=2bf446fc73cb
plaxdmin_1   | SHLVL=2
plaxdmin_1   | HOME=/root
plaxdmin_1   | PGID=1421
plaxdmin_1   | TIMEZONE=Europe/Paris
plaxdmin_1   | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
plaxdmin_1   | PLAXDMIN_DNS=plaxdmin.vba.ovh
plaxdmin_1   | PUID=1421
plaxdmin_1   | PWD=/opt/plaxdmin
plaxdmin_1   | PLAXDMIN_VERSION=v-202101312014-alpha
plaxdmin_1   | total 8
plaxdmin_1   | drwxr-xr-x    2 root     root          4096 Jan 31 17:59 .
plaxdmin_1   | drwxr-xr-x    1 root     root          4096 Jan 31 20:26 ..
plaxdmin_1   | total 12
plaxdmin_1   | drwxr-xr-x    3 root     root          4096 Jan 31 19:34 .
plaxdmin_1   | drwxr-xr-x    1 root     root          4096 Jan 31 20:15 ..
plaxdmin_1   | drwxr-xr-x    5 root     root          4096 Jan 31 19:34 portainer
plaxdmin_1   | total 8
plaxdmin_1   | drwxr-xr-x    2 root     root          4096 Jan 31 17:59 .
plaxdmin_1   | drwxr-xr-x    1 root     root          4096 Jan 31 20:15 ..
plaxdmin_1   | /opt/plaxdmin
plaxdmin_1   | root
plaxdmin_1   | 
plaxdmin_1   |         Can't find a suitable configuration file in this directory or any
plaxdmin_1   |         parent. Are you in the right directory?
plaxdmin_1   | 
plaxdmin_1   |         Supported filenames: docker-compose.yml, docker-compose.yaml
plaxdmin_1   |         
appdata_plaxdmin_1 exited with code 1

编辑: 为了更清楚地解释我的主要目标,我需要开发一个在撰写文件中作为单一服务运行的应用程序。我的应用程序分为 docker 容器(api、web 客户端、discord 客户端、数据库、代理,还有更多)。 所以我的代码被组织为一个元 topp 存储库,将所有其他存储库作为 git 子模块。当我提交元项目时,它会触发 dockerhub 上每个子图像的构建/发布。然后元项目构建一个图像,在 compose 文件中运行所有这些子图像/容器。您在上面看到的 Dockerfile 是针对那个元项目的。

编辑 2: 更新包含错误的 dockerfile。并添加 docker build 输出。

Step 1/13 : FROM docker/compose
latest: Pulling from docker/compose
aad63a933944: Pulling fs layer
b396cd7cbac4: Pulling fs layer
0426ec0ed60a: Pulling fs layer
9ac2a98ece5b: Pulling fs layer
9ac2a98ece5b: Waiting
b396cd7cbac4: Verifying Checksum
b396cd7cbac4: Download complete
aad63a933944: Verifying Checksum
aad63a933944: Download complete
0426ec0ed60a: Verifying Checksum
0426ec0ed60a: Download complete
9ac2a98ece5b: Verifying Checksum
9ac2a98ece5b: Download complete
aad63a933944: Pull complete
b396cd7cbac4: Pull complete
0426ec0ed60a: Pull complete
9ac2a98ece5b: Pull complete
Digest: sha256:b60a020c0f68047b353a4a747f27f5e5ddb17116b7b018762edfb6f7a6439a82
Status: Downloaded newer image for docker/compose:latest
 ---> c3e188a6b38f
Step 2/13 : ENV TIMEZONE=Europe/Paris
 ---> Running in 313daae863cf
Removing intermediate container 313daae863cf
 ---> d0dd8c94b9e3
Step 3/13 : ENV PLAXDMIN_DNS="plaxdmin.default.org"
 ---> Running in dbd36e109d3f
Removing intermediate container dbd36e109d3f
 ---> 5df13f4aec2c
Step 4/13 : ENV PLAXDMIN_VERSION="v-202101312014-alpha"
 ---> Running in 9085c5958ae5
Removing intermediate container 9085c5958ae5
 ---> 8b16db353f10
Step 5/13 : WORKDIR /var/log/plaxdmin
 ---> Running in 2f3dd94d0e75
Removing intermediate container 2f3dd94d0e75
 ---> d228994e7927
Step 6/13 : WORKDIR /etc/plaxdmin
 ---> Running in 92f3713bd54c
Removing intermediate container 92f3713bd54c
 ---> ef7a8736ba0b
Step 7/13 : ADD ./resources/conf/* ./
 ---> ee36033c9c5e
Step 8/13 : RUN ls -al ./
 ---> Running in 60bb92954ecf
total 20
drwxr-xr-x    1 root     root          4096 Jan 31 20:15 .
drwxr-xr-x    1 root     root          4096 Jan 31 20:15 ..
-rw-rw-rw-    1 root     root           262 Jan 31 02:06 application.properties
-rw-rw-rw-    1 root     root           690 Jan 31 02:06 log4j.properties
-rw-rw-rw-    1 root     root          1518 Jan 31 19:31 nginx.conf
Removing intermediate container 60bb92954ecf
 ---> c794e76b2cb3
Step 9/13 : WORKDIR /opt/plaxdmin/
 ---> Running in bf6ed28a47a8
Removing intermediate container bf6ed28a47a8
 ---> e2dcd4913ea3
Step 10/13 : ADD ./resources/docker-compose.yml ./
 ---> 1346e4e2d930
Step 11/13 : RUN ls -al ./
 ---> Running in 5ddbbe7f440f
total 12
drwxr-xr-x    1 root     root          4096 Jan 31 20:15 .
drwxr-xr-x    1 root     root          4096 Jan 31 20:15 ..
-rw-rw-rw-    1 root     root          2317 Jan 31 19:31 docker-compose.yml
Removing intermediate container 5ddbbe7f440f
 ---> f3013003a8ea
Step 12/13 : EXPOSE 80
 ---> Running in 229fc6cdbfe1
Removing intermediate container 229fc6cdbfe1
 ---> 21189a057021
Step 13/13 : CMD  docker -v     && docker-compose -v     && printenv     && ls -al /etc/plaxdmin     &&  ls -al /opt/plaxdmin/     &&  ls -al /var/log/plaxdmin/     && pwd     && whoami     && docker-compose up
 ---> Running in 9265e36232c1
Removing intermediate container 9265e36232c1
 ---> d94ccaeebf34
Successfully built d94ccaeebf34
Successfully tagged plaxdmin/full:v-202101312014-alpha

【问题讨论】:

  • 在您构建映像时,这些文件是否存在于您的当前目录中?
  • 您显示的 Dockerfile 没有 COPY 任何东西进入 /etc/plaxdmin;应该吗?
  • (看起来您正在尝试创建一个配置文件容器,该容器将安装到创建的容器中。Compose volumes: 选项指的是物理主机上的 Docker 命名卷或目录; 您不能将文件直接从一个容器挂载到另一个容器。我不知道这是否会成为您最终设置的问题。)
  • @tekki:是的。我想否则构建不会成功。
  • 你在该行之前设置了WORKDIR /var/log/plaxdmin

标签: docker dockerfile


【解决方案1】:

我通过撰写文件运行该图像;在其中,我映射了这些文件夹,以便它们可以在其父级中作为卷进行访问。我试图删除它们,现在它可以工作了。

我不确定这是最终的解决方案,因为我现在有 other troubles,因为我需要这些文件至少可以从主机读取,但这是以后的问题?

【讨论】:

    猜你喜欢
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多