dockerfile 完成构建后,供应商文件夹消失 [英] vendor folder disappears after dockerfile finish building

查看:37
本文介绍了dockerfile 完成构建后,供应商文件夹消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切.我的docker-compose.yml:

The title says it all. My docker-compose.yml:

swagger:
    container_name: "swagger"
    build:
      context: web/
      dockerfile: swagger/Dockerfile
    dns:
      - "8.8.8.8"
      - "10.0.0.2"
    volumes:
      - ./web/swagger:/var/www/swagger:delegated
      - ./web/api/controllers:/var/www/swagger/controllers:ro
      - ./web/swagger/vendor:/var/www/swagger/vendor


我的Dockerfile:

FROM php:zts-alpine3.11

RUN apk update && apk upgrade

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer

WORKDIR /var/www/swagger

COPY swagger/composer.json ./
COPY swagger/composer.lock ./
RUN composer install --no-scripts --no-autoloader

COPY swagger .
COPY api/controllers controllers

EXPOSE 80
CMD php -S 0.0.0.0:80


构建:

Building swagger
Step 1/11 : FROM php:zts-alpine3.11
 ---> d9293b396dfe
Step 2/11 : RUN apk update && apk upgrade
 ---> Using cache
 ---> f3ea600aa726
Step 3/11 : RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
 ---> Using cache
 ---> 4fe1237c5dc2
Step 4/11 : WORKDIR /var/www/swagger
 ---> Using cache
 ---> c669a7b04c35
Step 5/11 : COPY swagger/composer.json ./
 ---> c5e6e3bbb97f
Step 6/11 : COPY swagger/composer.lock ./
 ---> 01e36ce086ae
Step 7/11 : RUN composer install --no-scripts --no-autoloader
 ---> Running in e08f6cf0fd92
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 6 installs, 0 updates, 0 removals
  - Installing doctrine/lexer (1.2.0): Downloading (100%)         
  - Installing symfony/polyfill-ctype (v1.17.0): Downloading (100%)         
  - Installing symfony/yaml (v5.0.8): Downloading (100%)         
  - Installing symfony/finder (v5.0.8): Downloading (100%)         
  - Installing doctrine/annotations (1.10.2): Downloading (100%)         
  - Installing zircote/swagger-php (3.0.4): Downloading (100%)         
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
3 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Removing intermediate container e08f6cf0fd92
 ---> db2db0c4240b
Step 8/11 : COPY swagger .
 ---> 04936a4370a0
Step 9/11 : COPY api/controllers controllers
 ---> d996bb813094
Step 10/11 : EXPOSE 80
 ---> Running in 82abb1153d51
Removing intermediate container 82abb1153d51
 ---> d2be0a04a504
Step 11/11 : CMD php -S 0.0.0.0:80
 ---> Running in 73e3d941ec27
Removing intermediate container 73e3d941ec27
 ---> 1a4ae5218579

Successfully built 1a4ae5218579
Successfully tagged apogo3_swagger:latest


正如您所看到的,它构建得很好,我什至尝试在 RUN composer install --no-scripts --no-autoloader 命令之后通过 ssh 进入每一步,以查看供应商文件夹何时消失,但没有运气.它不会在 Dockerfile 构建过程中的任何时候消失,这让我怀疑我的 docker-compose.yml 文件,更具体地说是在 volumes 部分.我对 docker 很陌生,我可能误解了一些东西.


As you can see, it builds fine, and i even tried to ssh into every step after the RUN composer install --no-scripts --no-autoloader command, to see when the vendor folder disappear, but with no luck. It doesn't disappear at any point under the Dockerfile build process, which makes me question my docker-compose.yml file, more specifically in the volumes section. I am quite new to docker and i might have misunderstood something.

... 首先是能够构建它并在构建过程完成后保留供应商文件夹.其次,我希望生成的供应商文件夹保留在主机或容器中,以防止长时间构建.

... is first and foremost, to be able to build it and keep the vendor folder after the build process finishes. Secondly, i want the generated vendor folder to either be persisted in the host machine or in the container, to prevent long builds.

我想我很接近,任何事情都非常感谢!

I think i am close, anything is very appreciated!

推荐答案

您可以从 docker-compose.yml 文件中删除所有 volumes:.

You can just delete all of the volumes: from your docker-compose.yml file.

volumes: 是容器启动时的单向推送":它们总是从主机目录或命名卷中获取内容,并用它替换图像中的数据.(有一种特殊情况,当您第一次使用命名卷时,它会预先加载图像中的数据,但我不会依赖于此:Docker 永远不会更新卷内容,因为它可能包含用户数据,并且这在 Kubernetes 等集群环境中不起作用.)

volumes: are a one-way "push" at container startup time: they always take the content from the host directory or named volume and replace the data from the image with that. (There is a special case, the first time you use a named volume, where it gets preloaded with data from the image, but I wouldn't rely on this: Docker will never update the volume content because it might contain user data, and this doesn't work in clustered environments like Kubernetes.)

在您的设置中,您需要使用几个主机目录并用这些目录隐藏图像中的内容.特别是,您要从主机中取出空的 vendor 目录并隐藏图像中的 vendor 目录.(它不是命名卷,因此首次使用时填充卷"规则不适用.)

In your setup you're taking a couple of host directories and hiding the content from the image with those. In particular, you are taking the empty vendor directory from the host and hiding the vendor directory in the image. (It is not a named volume so the "populate the volume on first use" rule doesn't apply.)

您需要的所有内容都已在图像中的正确位置,因此您实际上根本不需要 volumes: 此处.这也有使镜像完全独立的优点:如果你需要在其他系统上运行它,你可以 docker push 到一个注册表,并从远程系统 docker 运行它,而无需单独的应用程序代码副本.(同样,这在 Kubernetes 等集群环境中基本上是必需的.)

All of the content you need is already in the image in the correct place, so you don't actually need volumes: here at all. This also has the advantage of making the image completely self-contained: if you need to run it on some other system, you can docker push it to a registry, and from the remote system docker run it without needing a separate copy of the application code. (Again, this is basically required in clustered environments like Kubernetes.)

这篇关于dockerfile 完成构建后,供应商文件夹消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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