Build Error - prepare environment: http: invalid Host header (exec.go:71:0s)

Hi, I am on Git Lab Runner version- 14.8.2 which uses go go1.17.7,

root@gitlab-runner:/home/my-runner/# gitlab-runner --version
Version:      14.8.2
Git revision: c6e7e194
Git branch:   14-8-stable
GO version:   go1.17.7
Built:        2022-03-01T17:18:25+0000
OS/Arch:      linux/amd64

-- Go Version
root@gitlab-runner:/home/my-runner/# go version
go version go1.20.7 linux/amd64

Build Error Log:-

Running with ts-runner 7.0.0 (7-Stable)
  on aws-ecr-push-runner testRCGHSFD, system ID: s_xxxxx
Preparing the "docker" executor
Using Docker executor with image docker:latest ...
Using helper image:  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh  (overridden, default would be  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-7-Stable )
Pulling docker image registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh ...
Using docker image sha256:630ee2cf8cfd93951bf25263eed72bcf45ee4d10ee30728062cb24d692986df7 for registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh with digest registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper@sha256:0c0ad93b6d1294f218c202f5d67a030ebfde445f159f43b0f502fd42ea786fa4 ...
Starting service docker:19-dind ...
Pulling docker image docker:19-dind ...
Using docker image sha256:fa3b7a5678ece1ea157bb3f4fb6372911ad054e9d271f09d6401fb53e6a8c97d for docker:19-dind with digest docker@sha256:c85365ad08c7f6e02ac962a8759c4a5b8512ea5c294d3bb9ed25fca52e9e22e5 ...
Waiting for services to be up and running (timeout 30 seconds)...
Using helper image:  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh  (overridden, default would be  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-7-Stable )
Using docker image sha256:630ee2cf8cfd93951bf25263eed72bcf45ee4d10ee30728062cb24d692986df7 for registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh with digest registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper@sha256:0c0ad93b6d1294f218c202f5d67a030ebfde445f159f43b0f502fd42ea786fa4 ...
*** WARNING: Service runner-testRCGHSFD-project-54-concurrent-0-0839c5e501fd17d5-docker-0 probably didn't start properly.
Health check error:
service "runner-testRCGHSFD-project-54-concurrent-0-0839c5e501fd17d5-docker-0-wait-for-service" timeout
Health check container logs:
2023-12-13T16:18:36.541070616Z waiting for TCP connection to 172.17.0.2 on [2375 2376]...
2023-12-13T16:18:36.541130107Z dialing 172.17.0.2:2376...
2023-12-13T16:18:36.541137047Z dialing 172.17.0.2:2375...
2023-12-13T16:18:40.616382613Z dialing 172.17.0.2:2376...
2023-12-13T16:18:40.616430053Z dialing 172.17.0.2:2375...
2023-12-13T16:18:43.688298645Z dialing 172.17.0.2:2376...
2023-12-13T16:18:43.688335675Z dialing 172.17.0.2:2375...
2023-12-13T16:18:46.760844120Z dialing 172.17.0.2:2375...
2023-12-13T16:18:46.760890638Z dialing 172.17.0.2:2376...
2023-12-13T16:18:49.833068711Z dialing 172.17.0.2:2376...
2023-12-13T16:18:49.833100132Z dialing 172.17.0.2:2375...
2023-12-13T16:18:52.904260258Z dialing 172.17.0.2:2376...
2023-12-13T16:18:52.904297942Z dialing 172.17.0.2:2375...
2023-12-13T16:18:55.976390782Z dialing 172.17.0.2:2375...
2023-12-13T16:18:55.976433258Z dialing 172.17.0.2:2376...
2023-12-13T16:18:59.048366723Z dialing 172.17.0.2:2375...
2023-12-13T16:18:59.048452961Z dialing 172.17.0.2:2376...
2023-12-13T16:19:02.120287501Z dialing 172.17.0.2:2375...
2023-12-13T16:19:02.120338912Z dialing 172.17.0.2:2376...
2023-12-13T16:19:05.192430513Z dialing 172.17.0.2:2375...
2023-12-13T16:19:05.192583516Z dialing 172.17.0.2:2376...
Service container logs:
2023-12-13T16:18:36.246800756Z mount: permission denied (are you root?)
2023-12-13T16:18:36.247088330Z Could not mount /sys/kernel/security.
2023-12-13T16:18:36.247108124Z AppArmor detection and --privileged mode might break.
2023-12-13T16:18:36.248922888Z mount: permission denied (are you root?)
*********
Using helper image:  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh  (overridden, default would be  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-7-Stable )
Using docker image sha256:630ee2cf8cfd93951bf25263eed72bcf45ee4d10ee30728062cb24d692986df7 for registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh with digest registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper@sha256:0c0ad93b6d1294f218c202f5d67a030ebfde445f159f43b0f502fd42ea786fa4 ...
Pulling docker image docker:latest ...
Using docker image sha256:aa93deb4ad1b0d89a24411a139b6867bd175cfc69e0e8e087bfc69911f99943d for docker:latest with digest docker@sha256:c90e58d30700470fc59bdaaf802340fd25c1db628756d7bf74e100c566ba9589 ...
Preparing environment
00:00
Using helper image:  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh  (overridden, default would be  registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-7-Stable )
Using docker image sha256:630ee2cf8cfd93951bf25263eed72bcf45ee4d10ee30728062cb24d692986df7 for registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh with digest registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper@sha256:0c0ad93b6d1294f218c202f5d67a030ebfde445f159f43b0f502fd42ea786fa4 ...
ERROR: Job failed (system failure): prepare environment: http: invalid Host header (exec.go:71:0s). Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

Here is my runner details.

[[runners]]
  name = "aws-ecr-push-runner"
  url = "https://gitlab.redacted"
  id = 12
  token = "glrt-XXXXX"
  token_obtained_at = 2023-12-13T10:48:34Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.docker]
    helper_image = "registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:alpine3.18-x86_64-v16.1.0-pwsh" 
    tls_verify = false
    image = "python:3.11"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0

Here is my gitlab ci.

# Simple example of CI to build a Docker container and push it to Amazon ECR
variables:
  DOCKER_REGISTRY: 12345678901.dkr.ecr.us-east-1.amazonaws.com
  AWS_DEFAULT_REGION: us-east-1
  APP_NAME: container-repo
  IMAGE_NAME: container-repo-image
  DOCKER_HOST: tcp://docker:2375
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""

publish:
  stage: build
  image: 
    name: docker:latest
  services:
    - docker:19-dind
  before_script:
    - apk add --no-cache curl jq python3 py3-pip
    - pip install awscli
    - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $DOCKER_REGISTRY
    - aws --version
    - docker info
    - docker --version
  script:
    - docker build -t $DOCKER_REGISTRY/$IMAGE_NAME:$CI_PIPELINE_IID .
    - docker push $DOCKER_REGISTRY/$IMAGE_NAME:$CI_PIPELINE_IID

How do I avoid the build error ?

Edited by Santosh Sahoo