I have a react running in this docker container, but for whatever reason “npm install” and “npm run build” are not being ran automatically once i run “docker-compose up –build”. I have had to go into my react container and run them in order for my build to be live in the container. I know these commands are not being ran because once I get into my container, I do not have a node_modules directory or a build directory. In order to get these directories to appear, I have to manually run npm i and npm run build.
Dockerfile
FROM node:14 AS build
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
RUN npm install -g serve
ENV REACT_APP_DIR /app/build
EXPOSE 80
CMD ["serve", "-s", "build", "-l", "80"]
DOCKER-COMPOSE.yaml
services:
django:
build:
context: ./customerAPI/ # Path to your Django app
dockerfile: Dockerfile
container_name: django
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./customerAPI:/app
ports:
- "8000:8000"
react:
build:
context: ./reactAirxcelPortal # Path to your React app
dockerfile: Dockerfile
container_name: react
volumes:
- ./reactAirxcelPortal:/app
ports:
- "80:80"
I have tried most of the solutions online, and everyone’s dockerfile looks similar to mine yet mine will not build automatically. I have tried chatGPT and several stackoverflow entries but no dice.
GilleyG is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.