title: How to set the name of a Docker container using REST API
body: <p>I am attempting to create and start a container via the REST API.  That is, using the following API:</p>
  
  <pre><code>curl --http1.0 --request POST --header "Content-Type: application.json" http://$DOCKER_HOST:4243/containers/create --data @create.json
  </code></pre>
  
  <p>where create.json is a JSON file of desired properties. I would like to assign a specific name to the container. One can do this via the docker CLI using the --name parameter on the run command:</p>
  
  <pre><code>docker run --name "my_name" my_image
  </code></pre>
  
  <p>The documentation for creating a container (<a href="https://docs.docker.com/reference/api/docker_remote_api_v1.15/#create-a-container" rel="nofollow">https://docs.docker.com/reference/api/docker_remote_api_v1.15/#create-a-container</a>) provides an example JSON payload. A name attribute is not listed.  I tried the following variations for a name attribute:</p>
  
  <pre><code>"Name": "my_name"
  "Names": [ "my_name" ]
  "Names": [ "/my_name" ]
  "Name": "/my_name"
  </code></pre>
  
  <p>all to no avail. The variations are inspired by the results of a query:</p>
  
  <pre><code>curl --http1.0 http://$DOCKER_HOST:4243/containers/json
  </code></pre>
  
  <p>which returns entries that include:</p>
  
  <pre><code>"Names":["/elegant_mccarthy"]
  </code></pre>