To resolve the favicon.ico 404 error in a React.js application running in a Docker container, you can follow these steps:

  1. Create a public folder in the root directory of your React.js project if it doesn't already exist.

  2. Place the favicon.ico file inside the public folder.

  3. Update the Dockerfile to include the COPY command to copy the public 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"]
    
  4. 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.

reactjs dist in docker faviconico 404

原文地址: http://www.cveoy.top/t/topic/i5GV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录