No connection could be made because the target machine actively refused it

Hi, I set up Elasticsearch, Kibana and a Fleet server as Docker containers on the same host in Azure. All the three are up and running with no issues. I am trying to install an Elastic agent on a Windows VM hosted locally (with Internet enabled using NAT) using the 'Enroll to Fleet server' method. However, I get the error as follows:

.\elastic-agent.exe install --url=https://redacted:8220 --enrollment-token=redacted
Elastic Agent will be installed at C:\Program Files\Elastic\Agent and will run as a service. Do you want to continue? [Y/n]:Y
[ ===] Service Started  [2s] Elastic Agent successfully installed, starting enrollment.
[==  ] Waiting For Enroll...  [3s] {"log.level":"info","@timestamp":"2024-08-13T23:00:58.034+0200","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/cmd.(*enrollCmd).enrollWithBackoff","file.name":"cmd/enroll_cmd.go","file.line":518},"message":"Starting enrollment to URL: https://redacted:8220/","ecs.version":"1.6.0"}
[==  ] Waiting For Enroll...  [13s] {"log.level":"info","@timestamp":"2024-08-13T23:01:13.580+0200","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/cmd.(*enrollCmd).enrollWithBackoff","file.name":"cmd/enroll_cmd.go","file.line":524},"message":"1st enrollment attempt failed, retrying enrolling to URL: https://redacted:8220/ with exponential backoff (init 1s, max 10s)","ecs.version":"1.6.0"}
Error: fail to enroll: fail to execute request to fleet-server: dial tcp redacted:8220: connectex: No connection could be made because the target machine actively refused it.
For help, please see our troubleshooting guide at https://www.elastic.co/guide/en/fleet/8.15/fleet-troubleshooting.html

[====] Uninstalled  [14s] Error uninstalling. Printing logs
2024-08-13T21:01:15.212Z        DEBUG   [install]       Loaded configuration from C:\Users\yolo\elastic-agent-8.15.0-windows-x86_64\elastic-agent.yml
2024-08-13T21:01:15.212Z        DEBUG   [install]       Merged configuration from C:\Users\yolo\elastic-agent-8.15.0-windows-x86_64\elastic-agent.yml into result
2024-08-13T21:01:15.212Z        DEBUG   [install]       Merged all configuration files from [C:\Users\yolo\elastic-agent-8.15.0-windows-x86_64\elastic-agent.yml], no external input files
2024-08-13T21:01:15.212Z        DEBUG   [install.composable]    Starting controller for composable inputs
2024-08-13T21:01:15.212Z        DEBUG   [install.composable]    Started controller for composable inputs
2024-08-13T21:01:15.213Z        DEBUG   [install.composable.providers.kubernetes]       Kubernetes provider for resource pod skipped, unable to connect: unable to build kube config due to error: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
2024-08-13T21:01:15.213Z        DEBUG   [install.composable.providers.kubernetes]       Kubernetes provider for resource node skipped, unable to connect: unable to build kube config due to error: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
2024-08-13T21:01:15.213Z        DEBUG   [install.composable]    Kubernetes leaderelection provider skipped, unable to connect: unable to build kube config due to error: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
2024-08-13T21:01:15.213Z        DEBUG   [install.composable]    Variable state changed for composable inputs; debounce started
2024-08-13T21:01:15.214Z        DEBUG   [install.composable]    kubernetes_secrets provider skipped, unable to connect: unable to build kube config due to error: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
2024-08-13T21:01:15.217Z        INFO    [install.composable.providers.docker]   Docker provider skipped, unable to connect: protocol not available
2024-08-13T21:01:15.391Z        DEBUG   [install.composable]    Computing new variable state for composable inputs
2024-08-13T21:01:15.391Z        DEBUG   [install.composable]    Stopping controller for composable inputs
2024-08-13T21:01:15.528Z        DEBUG   [install.composable]    Stopped controller for composable inputs
Error: enroll command failed for unknown reason: exit status 1
For help, please see our troubleshooting guide at https://www.elastic.co/guide/en/fleet/8.15/fleet-troubleshooting.html

I also attached the failed uninstallation log just in case it proves useful. I'd appreciate your help, thanks.

1 Like

Are you using an IP address that is accessible from the VM?
There is a similar question here, maybe it helps: windows - Docker says: No connection could be made because the target machine actively refused it - Stack Overflow

Check the cert validation from the host. It either needs to be a trusted CA, or use the insecure flag on the deployment.