Skip to main content

Command Palette

Search for a command to run...

Docker Command Bonus: Dockerizing React Apps

Published
2 min read

In a previous post on Dockerizing React Apps, I discussed a strategy for running React in a Docker container.

In the scripts, I put local-react as the image tag. You'll soon find out trying to use the same tag on all your containers is not the greatest idea!

For my local projects, I swap out local-react with ${PWD##*/}. This says "get the folder name". This way, not all my images are tagged the same, they are tagged with the folder they are contained in. This is typically the name of the project and is a great starter tag for the image. Sweet!

So, the new commands will look like the following:

To build:

docker build . -t ${PWD##*/}

To run:

docker run \
  -it \
  --rm \
  -v ${PWD}:/app \
  -v /app/node_modules \
  -p 3000:3000 \
  ${PWD##*/}

Happy programming!!

More from this blog

D

Dev Log by Michael Leners

6 posts

Former physics instructor, recovering engineer, graduate student, Washington native, and "Iowa Captive". I love web development and am especially passionate about the intersection of UX and QA.