"Create React Application" with Docker

I was wondering if anyone had experience using app-app-app with docker. I managed to configure it using Dockerfile, for example:

from node RUN mkdir /src WORKDIR /src ADD package.json /src/package.json RUN npm install EXPOSE 3000 CMD [ "npm", "start" ] 

And then used the file that creates the docker, for example:

 app: volumes: - "./app:/src" ports: - "3000:3000" - "35729:35729" build: ./app 

This allowed me to launch the container and view the application. However, when saving files in the mounted volume, the cookie did not work, and webpack created several .json.gzip files in the src directory.

Any suggestions for proper operation?

+7
docker reactjs webpack docker-compose livereload
source share
2 answers

I recently made a small project called hello-docker-react that just does what op is looking for.

It is created using an application to create docker, create-reaction-application, yarn, an image node and a small script entry point.

Live reboot works flawlessly and I have not found any problems yet.

https://github.com/lopezator/hello-docker-react

+6
source share

Yes, as aholbreich mentioned, I would use npm install / npm start locally on my development machine, simply because it is so simple. This may be possible with docker-compose , mounting volumes, etc., but I think it might be a little difficult to set up.

For deployment, you can very easily use the Docker file. Here is an example of a Dockerfile that I am using:

 FROM node:6.9 # Create app directory RUN mkdir -p /src/app WORKDIR /src/app # to make npm test run only once non-interactively ENV CI=true # Install app dependencies COPY package.json /src/app/ RUN npm install && \ npm install -g pushstate-server # Bundle app source COPY . /src/app # Build and optimize react app RUN npm run build EXPOSE 9000 # defined in package.json CMD [ "npm", "run", "start:prod" ] 

You need to add the start:prod option to your package.json:

 "scripts": { "start": "react-scripts start", "start:prod": "pushstate-server build", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, 

You can run tests in the CI service with:

 docker run <image> npm test 

There is nothing stopping you from starting this docker container to make sure everything is working as expected.

+5
source share

All Articles