2

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

3
  • @7_R3X investigating how to implement this in my current setup. Still new to docker ;) Commented Aug 21, 2019 at 13:07
  • After services section of the docker-compose file, you need to add a volumes section, define a volume and map that volume to both the services. Take a look at this Commented Aug 21, 2019 at 13:13
  • 1
    @7_R3X just found it and implemented it, it works. thank you very much will accept your answer Commented Aug 21, 2019 at 13:14

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.