Skip to content

Commit 6d3eb94

Browse files
committed
Dockerize React App - Create Docker Image
1 parent de433d7 commit 6d3eb94

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Dockerfile

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@ WORKDIR /usr/src/app
77
# add `/usr/src/app/node_modules/.bin` to $PATH
88
ENV PATH /usr/src/app/node_modules/.bin:$PATH
99

10+
# add environment variables
11+
ARG REACT_APP_USERS_SERVICE_URL
12+
ARG NODE_ENV
13+
ENV NODE_ENV $NODE_ENV
14+
ENV REACT_APP_USERS_SERVICE_URL $REACT_APP_USERS_SERVICE_URL
15+
1016
# install and cache app dependencies
1117
ADD package.json /usr/src/app/package.json
1218
RUN npm install --silent
1319
RUN npm install [email protected] -g --silent
20+
RUN npm install pushstate-server -g --silent
1421

1522
# add app
1623
ADD . /usr/src/app
1724

25+
# build react app
26+
RUN npm run build
27+
1828
# start app
19-
CMD ["npm", "start"]
29+
CMD ["pushstate-server", "build"]
2030

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,28 @@ $ python manage.py seed_db
3737
$ python manage.py runserver -p 5555
3838
```
3939

40+
## Other Command
41+
42+
To Build Docker image React App:
43+
```bash
44+
$ docker build -t "test" ./ --build-arg NODE_ENV=development --build-arg REACT_APP_USERS_SERVICE_URL=http://FLASK_SERVER_URL
45+
```
46+
To run the `test` image:
47+
```bash
48+
$ docker run -d -p 9000:9000 test
49+
```
50+
To view container's environment:
51+
```bash
52+
$ docker exec CONTAINER_ID bash -c 'env'
53+
```
54+
To stop and remove container:
55+
```bash
56+
$ docker stop CONTAINER_ID
57+
$ docker rm CONTAINER_ID
58+
```
59+
To remove the image:
60+
```bash
61+
$ docker rmi test
62+
```
63+
4064

0 commit comments

Comments
 (0)