DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Aravind Balla
Aravind Balla

Posted on • Originally published at hackernoon.com on

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

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!


Top comments (1)

Want to Create an Account?
Now it's your turn!
Β 
πŸ—’ Share a tutorial
πŸ€” Reflect on your coding journey
❓ Ask a question

Create an account to join hundreds of thousands of DEV members on their journey.