How to copy some data from one container to another container by docker-compose.yml

Now I am developing a React application. For the deployment I want to use nginx as the web server. I have written a docker-compose file with two services (One for React app and another for nginx webserver). Usually nginx service needs only the ‘build’ folder from the react project.

Now my question is how can I copy the ‘build’ folder from the react container to the nginx container directory when the react container is running.

Please take a look on the Dockerfiles and the yaml file.

docker-compose.yaml

version: "3"
services:
  nginx-server:    
    image: nginx_server:dev
    container_name: nginx
    build:
      context: ./nginx
      dockerfile: Dockerfile
    restart: always   

    command: >
      sh -c "cp -R /build/ /var/www/html/"   // I want to do something like that


    volumes:
      - .:/react_app_server/nginx

    ports:
      - 80:80
    depends_on:
      - react-app
    networks:
      - server_network


  react-app:
    container_name: my_react_app
    build:
      context: .
      dockerfile: ./Dockerfile
    image: my_react_app:dev 
    tty: true
    volumes:
      - .:/react_app
    ports:
      - "1109:1109"
    networks:
      - frontend_network
    command: >
      bash -c "npm run-script build"

networks:
  frontend_network:
    driver: bridge
  server_network:
    driver: bridge


volumes:
  static-volume:

Dockerfile for React app

FROM node:10.16.3
RUN mkdir /app
WORKDIR /app
COPY . /app
ENV PATH /app/node_modules/.bin:$PATH
RUN npm install --silent
RUN npm install [email protected] -g --silent
RUN npm run-script build

Dockerfile for Nginx

FROM nginx:1.16.1-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY /prod.conf /etc/nginx/conf.d

Project Directory

My_React_App
    build
    nginx
        Dockerfile
        prod.conf
    node_modules
    public
    src
    .dockerignore
    docker-compose.yaml
    Dockerfile
    package-lock.json
    package.json
    README.md

Source: StackOverflow