benzino77 / clamav-rest-api

ClamAV REST API. Scan files using simple POST request.
MIT License
105 stars 37 forks source link

ECONNREFUSED 127.0.0.1:3310 #29

Open slehernaf opened 2 years ago

slehernaf commented 2 years ago

I do not know why, but during startup, the container is displayed as active and disappears after 2-3 seconds, this error is found in the logs Cannot initialize clamav object: Error: connect ECONNREFUSED 127.0.0.1:3310 netstat -lnp | grep -E "(clam|3310|docker)" ->

netstat result

benzino77 commented 2 years ago

Hi! Do you have CRA and ClamAV started in docker?

slehernaf commented 2 years ago

No, i tried started with ClamAV in docker, but the error still remained

benzino77 commented 2 years ago

But CRA is started inside container? If so, you cannot use localhost/127.0.0.1 as Clamavd address because localhost/127.0.0.1 inside container is not the same as your host ;)

slehernaf commented 2 years ago

I'm sorry, I just started dealing with dockers and I don't understand a lot yet, so I can only give screenshots. Here is a port scan: netstat result Here it shows how the image is launched, that the container is created and disappears, and logs netstat result You can also see here that the container is running on 3310/tcp, this is the clamav/clamav image

benzino77 commented 2 years ago

OK. So here is the problem: you have not specified CLAMD_IP env variable for CRA container so it defaults to localhost/127.0.0.1 (you just copy paste command from README without pointing to proper config file). You have to set this environment variable to your host (computer you are running docker-engine) IP. You can do this by running CRA container with the command:

docker run -d -p 8080:8080 -e NODE_ENV=production -e APP_PORT=8080 -e APP_FORM_KEY=FILES -e CLAMD_IP=<put_here_ip_address_of_your_machine> benzino77/clamav-rest-api
sankar2389 commented 2 years ago

clamav/clamav:latest - I'm running the clamav docker container & ip address added in .env CLAMD_IP - 172.17.0.2

got this ip address by below command docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' de7a835c5681

But still getting error as ECONNREFUSED

Ist there any steps to follow?

benzino77 commented 2 years ago

You should not use it that way - that address will change every time you restart clamavd container. Have a look in the examples folder If you do not want to use docker-compose you should try to set up things like that:

  1. Get your host (the VM/machine on which docker -engine is running) IP address
  2. start clamvad as container and expose port 3310
  3. start CRA container and point CLAMD_IP to the IP from step 1
a-sarja commented 1 year ago

@benzino77 I m facing the same error. I am trying to start clamav-rest-api app by cloning the repo and running the clamav docker container locally. But for some reason, I am facing ECONNREFUSED error.

P.S - I have tried with setting the ENV variables in different ways (.env file and also as shown in the screenshot) with VM IP address, 127.0.0.1 and localhost for CLAMD_IP - but the result is the same

image

benzino77 commented 1 year ago

CRA will not start if there is no clamav daemon available (or I should rather say there is no clamavd with open 3310 port available). As I can see from the screenshot you provided you have not publish clamav port to the host. You should start clamav container by something similar to:

docker run -d --name clamavd -p 3310:3310 clamav/clamav:stable

The important part is -p 3310:3310

a-sarja commented 1 year ago

Thank you, that worked! I think it is better to update the README about the same, since I do not see this info there. Cheers!

benzino77 commented 1 year ago

Thank you, that worked! I think it is better to update the README about the same, since I do not see this info there. Cheers!

PRs are welcome ;)

Dunae commented 5 months ago

Hi i m running in kubernetes clamav and cra, i changed cra service type from nodeport to loadbalancer because i need an public ip for the endoint, is working for a day and after a day i receive { "success": false, "data": { "error": "connect ECONNREFUSED 10.0.0.86:3310" } }

benzino77 commented 5 months ago

Hi, That is because there is no clamav service available. Where do you try to start CRA: Docker? K8S?

could you please provide your setup: docker-compose.yaml or your k8s manifests?

Dunae commented 5 months ago

Hi, thank you for quick respose, please see the manifests below: apiVersion: apps/v1 kind: Deployment metadata: name: clamavd-deployment labels: app: clamavd spec: replicas: 1 selector: matchLabels: app: clamavd template: metadata: labels: app: clamavd spec: containers:

apiVersion: apps/v1 kind: Deployment metadata:

Unique key of the Deployment instance

name: cra-deployment labels: app: cra spec: replicas: 1 selector: matchLabels: app: cra template: metadata: labels:

Apply this label to pods and default

    # the Deployment label selector to this value
    app: cra
spec:
  containers:
    - name: clamav-rest-api
      # Run this image
      image: benzino77/clamav-rest-api
      command: ['/usr/bin/wait-for-it', '-h', 'clamavd-service', '-p', '3310', '-s', '-t', '60', '--', 'npm', 'start']
      env:
        - name: NODE_ENV
          valueFrom:
            configMapKeyRef:
              name: cra-configmap
              key: node-env
        - name: CLAMD_IP
          valueFrom:
            configMapKeyRef:
              name: cra-configmap
              key: clamd-ip
        - name: APP_FORM_KEY
          valueFrom:
            configMapKeyRef:
              name: cra-configmap
              key: app-form-key
        - name: APP_MAX_FILE_SIZE
          valueFrom:
            configMapKeyRef:
              name: cra-configmap
              key: app-max-file-size
      ports:
        - containerPort: 3000
          protocol: TCP
          name: cra-port

apiVersion: v1 kind: Service metadata: name: cra-service annotations:

service.beta.kubernetes.io/azure-load-balancer-internal: "true"

spec: type: LoadBalancer selector: app: cra ports:

is working for a day lets say and next day the error