Search code examples
reactjsnode.jsdockercontainersreact-fullstack

How to ship Node.js API and React.js in single Docker Container?


How can I efficiently package and deploy multiple related applications (React frontend and Node.js backend) within a single container? Where containers are meant to be single-process deployments and common statement heard in topic of serving static files with Node.js are performance issues.My current approach involves separate Dockerfiles for each application, using NGINX for the frontend and Node.js for the backend.


Solution

  • It's not worthly to worry about performance before application gets deployed at the first place, there is much unknowns in area for optimalization such as requests per second, bundle size, complexity of operations and so on.

    By the problem presented in question I was really looking for serving out static content by Node.js server which reduces deployment to single container, and by such deployment and operational costs - it was optimal solution in budget where in fact application up to this day has not hit any performance bottlenecks that would make production not able to be used.

    Key takes:

    • Containers are meant to be single-process deployments, which means they should not hold running Node.js API and Nginx in one container - for this purpose it's better to create two separate containers as it's easier to manage.
    • Serving static assets with Node.js was not a problem for the usecase I had trouble with, application at the production was roughly ~1 RPM (if so) and even if there are performance bottlenecks it's often not worthly to pay for two container deployments instead one that will serve front-end and back-end. (by "not worthly" I assume serving application on budget for ex. PaaS that will bill per container running)

    Disclaimer

    This answer was rewritten along the question to make it more informative for newcommers who may have similar problem. Previously I've come down to using Meteor.js which have seem to resolve my problem yet I did not understand the problem as a whole.