Reputation: 472
I am working on app that has a webserver running openresty and a application running on php wit the front-end in vue.
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
When building the application I am building my vue code to a dist folder this happens inside the php container:
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
now inside the php docker container is a new folder dist under /var/www/dist.
nginx needs to use this folder because it contains a static index.html which is served by nginx like this
location / {
alias /var/www/company/dist/;
try_files $uri $uri/ /index.html;
}
I am wondering how I can my web container access the build folder dist which is located inside the php container
Thanks in advance
Upvotes: 2
Views: 412
Reputation: 4370
You can use bind-mounts to mount that folder from the host.
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.
Or, you can use docker volume and attach that volume to both the containers.
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.
Edit: Link to Official document of docker-volume implementation
Upvotes: 4