If you don't need to make it a two step process, you could do everything within one Dockerfile and then remove the dependencies needed for the installation afterwards.
I wrote a tutorial on the setup a little while back. Although it's directly with an alpine base.
Deploying ReactJS With Docker
The Dockerfile I wrote was:
NOTE: you could replace npm with yarn
File: Dockerfile
FROM alpine
EXPOSE 80
ADD config/default.conf /etc/nginx/conf.d/default.conf
COPY . /var/www/localhost/htdocs
RUN apk add nginx && \
mkdir /run/nginx && \
apk add nodejs && \
apk add npm && \
cd /var/www/localhost/htdocs && \
npm install && \
npm run build && \
apk del nodejs && \
apk del npm && \
mv /var/www/localhost/htdocs/build /var/www/localhost && \
cd /var/www/localhost/htdocs && \
rm -rf * && \
mv /var/www/localhost/build /var/www/localhost/htdocs;
CMD ["/bin/sh", "-c", "exec nginx -g 'daemon off;';"]
WORKDIR /var/www/localhost/htdocs
File used for nginx configuration
File: default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
root /var/www/localhost/htdocs/build;
# this will make so all routes will lead to
# index.html so that react handles the routes
try_files $uri $uri/ /index.html;
}
# You may need this to prevent return 404 recursion.
location = /404.html {
internal;
}
}
Hope this helps as a possible alternative.
react-scriptsis in package.json?