Docker Command Bonus: Dockerizing React Apps

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!!