Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get ERR_EMPTY_RESPONSE when starting a react via docker?

Tags:

docker

reactjs

I have such an app structure:

react-client
server
docker-compose.yaml

golang server normally starts in docker. And now I want to run react there. Here is my docker file for react-client

FROM node:alpine
WORKDIR /app/react
COPY package.json /app/react
COPY package-lock.json /app/react
COPY . /app/react
EXPOSE 3001
RUN npm i
CMD ["npm", "run", "start"]

my docker-compose file:

version: '3'

services:
    postgres:
        image: postgres:12
        restart: always
        ports:
            - '5432:5432'    
        volumes:
            - ./db_data:/var/lib/postgresql/data
            - ./server/scripts/init.sql:/docker-entrypoint-initdb.d/create_tables.sql
        env_file:
            - ./server/config/.env    
        healthcheck:
            test: [ "CMD", "pg_isready", "-q", "-d", "devdb", "-U","postgres" ]
            timeout: 45s
            interval: 10s
            retries: 10
    redis:
        image: redis:6.2
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock      
        ports:
          - 6379:6379 
    prometheus:
        image: "prom/prometheus:v2.21.0"
        ports:
          - "9090:9090"
        command:
          - "--config.file=/etc/prometheus/prometheus.yml"
        volumes:
          - "./server/metrics/prometheus.yml:/etc/prometheus/prometheus.yml:ro"
    grafana:
        image: grafana/grafana:6.1.6
        environment:
          - GF_AUTH_DISABLE_LOGIN_FORM=true
          - GF_AUTH_ANONYMOUS_ENABLED=true
          - GF_AUTH_ANONYMOUS_ORG_NAME=Main Org.
          - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
          - GF_USERS_ALLOW_SIGN_UP=false
        ports:
          - "3000:3000"
        volumes:
          - ./grafana/provisioning:/etc/grafana/provisioning
          - ./grafana/dashboards:/var/lib/grafana/dashboards
    web-client:
        build:
          context: ./react-client
          dockerfile: Dockerfile
        ports:
          - "3001:3001"
    app:
        build: 
          context: ./server
          dockerfile: Dockerfile
        ports:
          - 8080:8080
        depends_on:
          - postgres
          - redis

And now when you start docker and when i go to localhost:3001 i get an error: ERR_EMPTY_RESPONSE.

And I can't figure out what's wrong.If I run docker without react and run it via npm start then everything works fine. Maybe somehow not the whole project is copied?

Edit

I tried to do so

web-client:
        build:
          context: ./react-client
          dockerfile: Dockerfile
        ports:
          - "127.0.0.1:3001:3001"

but nothing has changed

I started the react separately on port 3000 and it starts fine.Apparently some kind of error occurs when starting on port 3001, but it is unclear what is wrong

like image 699
Omegon Avatar asked May 31 '26 03:05

Omegon


1 Answers

I suggest you to build an image for react-client and start a container manually. First change your Dockerfile:

FROM node:alpine
WORKDIR /app/react
COPY . .
EXPOSE 3001
RUN npm i
CMD ["npm", "run", "start"]
  • Then go into react-client directory and run docker build -t test .
  • Start container: docker run -d --name mytest -p 3001:3001 test
  • Check logs: docker logs mytest
  • Check if the whole project is copied: docker run --rm test ash -c "find /app/react -type f -print0 | xargs -0 ls -t"
like image 101
Slava Kuravsky Avatar answered Jun 02 '26 15:06

Slava Kuravsky