Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing args to container through docker API

I want to create and start a docker container with some arguments (to the CMD) through docker API using a json file.

curl -XPOST --unix-socket /var/run/docker.sock -d @minio.json -H 'Content-Type: application/json' http://localhost/containers/create?name=minio
curl -XPOST --unix-socket /var/run/docker.sock -H 'Content-Type: application/json' http://localhost/containers/minio/start

I tried to put them in the top of the json and the HostConfig "sub entry"

"Args": "server --address 192.168.150.3:80 /export",

but when I inspect the arguments are not there.

In the documentation there are examples only when you inspect a container and see the arguments.

Is there a way to pass Args within the json file or when you start the container with curl and a payload ("docker run" is excluded) ?

UPDATE:

Solution is to list all arguments in double quotes in the array.

"Cmd": [
"server" ,"--address", "192.168.100.8:8888", "/export"
],
like image 829
ady8531 Avatar asked Sep 11 '25 08:09

ady8531


1 Answers

The API has two attributes in JSON

   "Cmd": [
           "date"
   ],
   "Entrypoint": "",

You need to change the Cmd array to pass the arguments you want

like image 69
Tarun Lalwani Avatar answered Sep 13 '25 22:09

Tarun Lalwani