DEV Community

Aravind Balla
Aravind Balla

Posted on • Originally published at hackernoon.com on

3 2

Docker workflow for React/Web applications

I have been fiddling with React lately. Built my website on it. I did not face a huge problem while deploying as this is a static site. But, generally we face problems in deployment. It runs on our local, but doesn’t run in production. Common problem, right?

If you know Docker, then you might be wondering, why doesn’t he come straight to the point!

Yes, using Docker, we have the same environment while development and production. Even testing, if you choose to do it.

Using docker for production is easy. We just have to

ADD . /var/www/
WORKDIR /var/www/
view raw .Dockerfile hosted with ❤ by GitHub

in the Dockerfile from the current working directory to copy our code to the docker container. This gets all our code in the container and we can run commands in it. All we have to do it is run the container and expose the port on which the server is running. We now can take this container and scale these up from performance if needed.

But, if we want to dockerize even our development workflow, its a bit different.

We have to use the concept of mounting volumes to the container. We mount the current working directory to a directory in the container while starting it by adding

-v /host/directory:/container/directory

to the docker run command. Any changes in the host directory will be reflected in the container as well. So this can be used for development.

So the mixed workflow can consist of two dockerfiles, one for development and one for production. And while running it for development we have to mount the directory to it.

By using this workflow, we can guarantee that the development and production have the same environments.

Keep on Hacking!


Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay