0

Details

I'm trying to deploy a React.js project to docker, but the App.css styles aren't being applied to the HTML elements. The App.css file is being properly imported and can be found in the page sources, but the elements aren't applying their classes.

Configuration

Dockerfile


FROM node:20.10.0 AS build

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build

FROM nginx:latest

COPY --from=build /app/build /usr/share/nginx/html

COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

nginx.conf


worker_processes 1;

events {
  worker_connections 1024;
}

http {
  sendfile on;

  server {
    listen 80;
    server_name localhost;

    location / {
      root /usr/share/nginx/html;
      index index.html;
      try_files $uri $uri/ /index.html;
    }
  }
}

Client pictures

enter image description here

enter image description here

enter image description here

Conclusion

It's possible that I might have misconfigured like package.json or some other React.js component that has an impact on this. I'm still very new to react and might have deleted some important setting or something.

Any help or suggestions would be greatly appreciated

1

1 Answer 1

0

There might be issue with the way you copy package.json. Try removing the asterisk. Here is the dockerfile I used and it worked perfectly

#Specify the base image
FROM node:14.14.0-alpine as builder

#Specify the workdir
WORKDIR /app

#Copy the package json
COPY ./package.json ./

#Install dependencies
RUN npm install

#Copy all files and folders
COPY ./ ./

#Create build
RUN npm run build


#Start new image creation
FROM nginx

#Expose port
EXPOSE 3000

#Copy default.conf file
COPY ./nginx/default.conf ./etc/nginx/conf.d/

#Copy files from the previous image
COPY --from=builder ./app/build ./usr/share/nginx/html
Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately this didn't solve the problem. My project is public --> github.com/ronanski11/Teezinator/tree/main/teezinator-client. Maybe there is an obvious mistake i missed..?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.