reactjs dist in docker faviconico 404
To resolve the favicon.ico 404 error in a React.js application running in a Docker container, you can follow these steps:
-
Create a
public
folder in the root directory of your React.js project if it doesn't already exist. -
Place the
favicon.ico
file inside thepublic
folder. -
Update the
Dockerfile
to include theCOPY
command to copy thepublic
folder into the container.# Dockerfile FROM node:14-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . # Add the following line COPY public ./public EXPOSE 3000 CMD ["npm", "start"]
-
Rebuild the Docker image and run the container again.
docker build -t my-react-app . docker run -p 3000:3000 my-react-app
Now, the favicon.ico file should be accessible without any 404 errors.
原文地址: http://www.cveoy.top/t/topic/i5GV 著作权归作者所有。请勿转载和采集!