gpt4 book ai didi

php - Docker:如何在两个容器之间共享文件夹

转载 作者:行者123 更新时间:2023-12-02 18:10:31 27 4
gpt4 key购买 nike

我正在开发一个具有运行openresty的网络服务器和一个在vue前端运行php的应用程序的应用程序。

version: '3'
services:
php:
build: ./
volumes:
- ./services/php/php.ini:/usr/local/etc/php/php.ini

web:
build: ./services/openresty
ports:
- "8888:80"
volumes:
- ./services/openresty/company.conf:/usr/local/openresty/nginx/conf/nginx.conf
- ./services/openresty/bodyconfig.conf:/etc/openresty/nginx/conf/bodyconfig.conf

在构建应用程序时,我正在将我的Vue代码构建到dist文件夹中,这发生在php容器内:
FROM php:7.3-fpm-alpine

RUN apk update \
&& apk add --no-cache git curl libmcrypt libmcrypt-dev openssh-client icu-dev \
libxml2-dev bash freetype-dev libpng-dev libjpeg-turbo-dev nodejs npm libzip-dev g++ make autoconf postgresql-dev \
&& docker-php-source extract \
&& pecl install redis \
&& docker-php-ext-enable redis \
&& docker-php-source delete \
&& docker-php-ext-install pdo_pgsql soap intl gd zip \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& rm -rf /tmp/*

CMD ["php-fpm", "-F"]

WORKDIR /var/www/company

COPY ./ ./

RUN bash ./docker_build.sh

EXPOSE 9000

docker_build.sh
cd /var/www/company/js

npm install
npm run build

现在,在php docker容器内的/ var / www / dist下是一个新文件夹dist。

nginx需要使用此文件夹,因为它包含一个静态index.html,它由nginx像这样提供
location / {
alias /var/www/company/dist/;
try_files $uri $uri/ /index.html;
}

我想知道我的Web容器如何访问位于php容器内的构建文件夹dist

提前致谢

最佳答案

您可以使用bind-mounts从主机挂载该文件夹。

Bind mount

When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its full or relative path on the host machine.



或者,您可以使用 docker volume并将该卷附加到两个容器。

Docker Volume

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind-mounts are dependent on the directory structure of the host machine, volumes are completely managed by Docker.



编辑:
链接到 Official document of docker-volume implementation

关于php - Docker:如何在两个容器之间共享文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57591864/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com