Jenkins server can't access jenkins agent

Hi, I am trying to deploy jenkins server and jenkins agent using Docker Compose.
Here you can check my docker compose yml:

version: '3'

services:
  jenkins-server:
    image: jenkins/jenkins:lts
    ports:
      - "8080:8080"
      - "50000:50000"
    volumes:
      - jenkins-data:/var/jenkins_home
    environment:
      - JENKINS_SLAVE_AGENT_PORT=50000
    networks:
      - jenkins

  jenkins-docker:
    image: docker:dind
    container_name: jenkins-docker
    privileged: true
    environment:
      - DOCKER_TLS_CERTDIR=/certs
    volumes:
      - jenkins-docker-certs:/certs/client
      - jenkins-data:/var/jenkins_home
    ports:
      - "2376:2376"
    networks:
      jenkins:
        aliases:
          - docker
    command: --storage-driver overlay2

  jenkins-agent:
    image: jenkins/ssh-agent:alpine-jdk17
    ports:
      - "2222:22"
    environment:
      - JENKINS_AGENT_SSH_PUBKEY="my_key"
    networks:
      - jenkins

networks:
  jenkins:

volumes:
  jenkins-data:
  jenkins-docker-certs:

I am trying to use official documentation instruction where we generating ssh key, add Credentials, then add agent container, restarting server, adding new node (agent) with our data and access agent via ssh private and pub keys.

But when I run my agent I would get connection refused error (and sometimes new ones):

SSHLauncher{host='jenkins-agent', port=22, credentialsId='jenkins', jvmOptions='', javaPath='', prefixStartSlaveCmd='', suffixStartSlaveCmd='', launchTimeoutSeconds=60, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.KnownHostsFileKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
[08/13/23 12:59:51] [SSH] Opening SSH connection to jenkins-agent:22.
/var/jenkins_home/.ssh/known_hosts [SSH] No Known Hosts file was found at /var/jenkins_home/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
SSH Connection failed with IOException: "Key exchange was not finished, connection is closed.", retrying in 15 seconds. There are 10 more retries left.
/var/jenkins_home/.ssh/known_hosts [SSH] No Known Hosts file was found at /var/jenkins_home/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
SSH Connection failed with IOException: "Key exchange was not finished, connection is closed.", retrying in 15 seconds. There are 9 more retries left.
/var/jenkins_home/.ssh/known_hosts [SSH] No Known Hosts file was found at /var/jenkins_home/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
SSH Connection failed with IOException: "Key exchange was not finished, connection is closed.", retrying in 15 seconds. There are 8 more retries left.
/var/jenkins_home/.ssh/known_hosts [SSH] No Known Hosts file was found at /var/jenkins_home/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
SSH Connection failed with IOException: "Key exchange was not finished, connection is closed.", retrying in 15 seconds. There are 7 more retries left.
/var/jenkins_home/.ssh/known_hosts [SSH] No Known Hosts file was found at /var/jenkins_home/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.

Secon error:

SSHLauncher{host='jenkins-agent', port=22, credentialsId='jenkins', jvmOptions='', javaPath='', prefixStartSlaveCmd='', suffixStartSlaveCmd='', launchTimeoutSeconds=60, maxNumRetries=10, retryWaitTime=15, sshHostKeyVerificationStrategy=hudson.plugins.sshslaves.verifiers.ManuallyTrustedKeyVerificationStrategy, tcpNoDelay=true, trackCredentials=true}
[08/13/23 13:09:05] [SSH] Opening SSH connection to jenkins-agent:22.
[08/13/23 13:09:05] [SSH] The SSH key with fingerprint 42:e9:1f:f4:ee:ad:b0:f9:5b:79:f8:bd:a5:5f:6d:d3 has been automatically trusted for connections to this machine.
/var/jenkins_home/.ssh/known_hosts [SSH] No Known Hosts file was found at /var/jenkins_home/.ssh/known_hosts. Please ensure one is created at this path and that Jenkins can read it.
Key exchange was not finished, connection is closed.
SSH Connection failed with IOException: "Key exchange was not finished, connection is closed.", retrying in 15 seconds. There are 3 more retries left.
ERROR: Server rejected the 1 private key(s) for jenkins (credentialId:jenkins/method:publickey)
[08/13/23 13:09:06] [SSH] Authentication failed.
Authentication failed.
[08/13/23 13:09:06] Launch failed - cleaning up connection
[08/13/23 13:09:06] [SSH] Connection closed.

Ashutosh Saxena has used docker compose with ssh agents in a Google Summer of Code 2023 project. You may be able to use the same techniques that are used in the repository where Ashutosh is doing development.