React dev environment with docker
Requires: React,Node,Npm,Docker,Docker-cli
- Create a
ui
dir with atest file
in it.
>$ docker run -it --rm -v ${PWD}/ui:/app node:<VERSION>-alpine sh
It downloads a node alpine image (docker registry) then exec into the container and access the shell.
CD
into container app, and locatetest.txt
file.- If found there,then remove ui folder
- Mount React app here:
npx create-react-app ui
- Create Dockerfile
- Building image off node alpine:
docker build -t reactdock
- reactdock is now a new image built off the alpine 'base' image, and it can be used to run a react application.
Mounted app container
- Flags: it (interactive), rm (remove afterwards), v (mounting), p (ports:3001 local to env and 3000 local to container), e(env polling changes)
docker run -it --rm -v ${PWD}/ui:/app -p 3001:3000 -e CHOKIDAR_USEPOLLING=true <imageName>
Mounted reactdock container
- Create
docker-compose
file - Remove any running docker images, add exec flags to compose file
- Type:
docker-compose up --build
- Clone repository
- Read top/bottom if needed
- Only type this in terminal:
docker-compose up --build
to create image/ run container.
💯