Passing build run parameters to Docker Agent Template

Hello!
I have a case where I want to run containers on a certain Docker host, which has been connected to the controller via Docker API setup. I would like to set the hostname of the container using a variable set in the Job Pipeline, which will be a computed string and will change on every new run. I am setting node for the job using the label set in Docker Agent Template:

    agent {
        label 'my-agent'
    }

image

The only way to set a hostname I found, is through the Container Settings in the Docker Agent Template configuration. But it will assign a fixed hostname to all the containers created.

Is there a way to pass the hostname from Jenkins pipeline?

Can you not set it with args?

So something like

docker {
  label 'foo'
  args '-H foo.com'
}

There are reasons why I am not using the docker keyword:

  1. When agents are used in this way, the job runs occupy an executor on the agent, thus the number of containers I can start will be limited to the number of executors on the agent machine. This is not the case for dynamic agents launched using Docker Cloud.
  2. I am using a Windows machine that runs Docker, so I cannot override the working directory, as mentioned in this issue.