9

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

Omegon
  • 387
  • 2
  • 10
  • Can you confirm node is running and listening in the container? From the node console/log. – Daniel W. Nov 18 '22 at 21:33
  • @DanielW. After launching docker-compose, if i go to webclient inside container, it writes that it is listening on ```0.0.0.0:3001```. I don't know how else to proof – Omegon Nov 18 '22 at 22:14
  • @Omegon exec into the web-client container and do `curl 127.0.0.1:3001` you might need to install curl first inside container. Also to check your environment, run this `docker run --name gettingstarted -d -p 80:80 docker/getting-started` see if you can see the the docker getting started page on your host machine localhost:80 – zsolt Nov 19 '22 at 20:12
  • @Omegon, can you post the `start` script in your `package.json` file? – Emanuele Scarabattoli Nov 21 '22 at 14:08
  • is [this article](https://kinsta.com/knowledgebase/err_empty_response/) answers your question? – Erhan Yaşar Nov 22 '22 at 22:09
  • did you check if your docker file has an extension? – monim Nov 23 '22 at 05:22
  • What are the logs from `web-client` seen with `docker logs` ? They may provide some info – Pierre B. Nov 23 '22 at 17:41
  • [This](https://stackoverflow.com/a/46203897/258174) is most likely your problem. Bind to `0.0.0.0` within your app, not `127.0.0.1`. – morganney Nov 24 '22 at 14:57
  • Should the CMD be "npm", "start"? – Joseph Walsh Nov 25 '22 at 10:56

1 Answers1

1

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"
Slava Kuravsky
  • 2,702
  • 10
  • 16