Minimal Dockerfile
Below is a Dockerfile that deploys a Create React App client with a Rails API server:-
A
reactbuild stage based on thenode:slimimage and consisting of twoRUNsteps: one that creates a react app, and one that builds it. -
An
--apiflag is added to therails newcommand. -
A
COPYstatement copies the build artifacts to the demo application’s public directory. -
RAILS_SERVE_STATIC_FILESis set to true. This is necessary as[[statics]]won’t find index.html files at the root. Even so, adding a statics section to thetomlfile is useful for the remainder of the bundled assets:
Example
Following is a example that demonstrates a React client working with a Rails API server. First the React client:COPY statement to add the .node-version
information to the image, and a controller that returns various
version strings as a JSON object.