title: How to copy build files from one container to another or host on docker
body: <p>I am trying to dockerize application where I have a php backend and vuejs frontend. Backend is working as I expect however after running <code>npm run build</code> within the frontend container, I need to copy build files from dist folder to nginx container or to host and then use volume to bring those files to nginx container.</p>
  <p>I tried to use named volume</p>
  <pre><code>services:
    frontend:
    .....
    volumes:
    - static:/var/www/frontend/dist
  
   nginx:
    .....
    volumes:
    - static:/var/www/frontend/dist
  
  volumes:
    static:
  </code></pre>
  <p>I also tried to do following as suggested on here to bring back dist folder to host</p>
  <pre><code>services:
    frontend:
    .....
    volumes:
    - ./frontend/dist:/var/www/frontend/dist
  </code></pre>
  <p>However none of the above options is working for me. Below is my docker-compose.yml file and frontend Dockerfile</p>
  <pre><code>version: &quot;3&quot;
  
  services:
  
    database:
     image: mysql:5.7.22
     .....
  
    backend:
      build:
        context: ./docker/php
        dockerfile: Dockerfile
      .....
  
    frontend:
      build:
        context: .
        dockerfile: docker/node/Dockerfile
        target: 'build-stage'
      container_name: frontend
      stdin_open: true
      tty: true
      volumes:
        - ./frontend:/var/www/frontend
  
    nginx:
      build:
        context: ./docker/nginx
        dockerfile: Dockerfile
      container_name: nginx
      restart: unless-stopped
      ports:
        - 80:80
      volumes:
        - ./backend/public:/var/www/backend/public:ro
        - ./frontend/dist:/var/www/frontend/dist:ro
      depends_on:
        - backend
        - frontend
  </code></pre>
  <p>Frontend Dockerfile</p>
  <pre><code># Develop stage
  FROM node:lts-alpine as develop-stage
  WORKDIR /var/wwww/frontend
  COPY /frontend/package*.json ./
  
  RUN npm install
  COPY /frontend .
  
  # Build stage
  FROM develop-stage as build-stage
  RUN npm run build
  </code></pre>