【发布时间】:2020-09-11 00:34:51
【问题描述】:
标题说明了一切。我的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 很陌生,我可能误解了一些东西。
我想要什么
... 首先是能够构建它并在构建过程完成后保留供应商文件夹。其次,我希望生成的供应商文件夹要么保存在主机中,要么保存在容器中,以防止长时间构建。
我想我很接近,任何事情都非常感谢!
【问题讨论】:
-
您应该能够删除所有
volumes:指令。这将使用RUN composer install创建的vendor目录和您COPY中的其他源代码,而不是将这些隐藏在可能为空的主机目录后面。 Docker 镜像缓存可以帮助最小化重建时间,利用这一点主要需要先复制composer.json文件(你有);你不需要卷。 -
非常感谢!发送答案,我会接受并投票 :-)
标签: docker docker-compose swagger