React 도커

신상우·2023년 12월 20일

쿠버네티스

목록 보기
9/26

npx create-react-app my-app react 설치

npm run start 시

문제발생
One of your dependencies, babel-preset-react-app, is importing the
"@babel/plugin-proposal-private-property-in-object" package without
declaring it in its dependencies. This is currently working because
"@babel/plugin-proposal-private-property-in-object" is already in your
node_modules folder for unrelated reasons, but it may break at any time.

babel-preset-react-app is part of the create-react-app project, which
is not maintianed anymore. It is thus unlikely that this bug will
ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to
your devDependencies to work around this error. This will make this message
go away.

https://inblog.ai/devgrr/897

$ npm install --save-dev @babel/plugin-proposal-private-property-in-object --legacy-peer-deps

OR

$ yarn install -D @babel/plugin-proposal-private-property-in-object --legacy-peer-deps

dockerfile.dev 를 실행시

docker build -f dockerfile.dev -t shinsang97/이름 ./

팁! 도커 환경에서 노드 모듈을 지워주는게 좋음 어차피 npm install을 하기떄문에

docker run -it -p 3000:3000 shinsang97/docker-react-app
으로 실행

docker run -it -p 3000:3000 -v /usr/src/app/node_modules -v ${pwd}:/usr/src/app shinsang97/docker-react-app

windows 에서 볼륨 적용안될때
dockerfile에 추가

ENV CHOKIDAR_USEPOLLING=true

windows 에서 안됌!!!

너무 긴 명령어 를 compose 를통해서
docker-compose.yml 파일에
version: '3'
services:
react:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- '3000:3000'
volumes:
- /usr/src/app/node_modules
- ./:/usr/src/app
environment:
- CHOKIDAR_USEPOLLING=true
stdin_open: true

넣고 docker-compose up 으로 실행

dockerfile 에
FROM node:alpine as builder
WORKDIR '/usr/src/app'
COPY package.json ./
RUN npm install
COPY ./ ./
RUN npm run build

FROM nginx
COPY --from=builder /usr/src/app/build /usr/share/nginx/html
추가하고
docker build . 후
docker run -p 8080:80 shinsang97/doecker-react-app 으로 실행

profile
기록 남기기

0개의 댓글