Assuming you've set up your project as described in the
usage with create-react-app guide, then all you need to
build a docker image for building and serving your app is using the following
Dockerfile
:
FROM staticdeploy/app-server:cra-builder
FROM staticdeploy/app-server:cra-runtime
The first FROM
instruction will run the ONBUILD
instructions of the
:cra-builder
image, which will install dependencies with yarn
and build the
app with yarn build
.
The second FROM
instruction will copy the built app into the (relatively)
small :cra-runtime
image where app-server
is installed and configured to
serve the app.
You can then run your app image passing in configuration via environment variables:
docker run -e APP_CONFIG_MY_VAR=my_val my-app-image
Note: the
Dockerfile
-s for thestaticdeploy/app-server:*
images can be found in the docker-app-server repository