0

Im trying to create a container from another container using the docker api v1.24.

I have managed to get the container created and started by using this line of code:

exec(`curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d \'{"Image": "strategy_baseline", "Hostname": "test","ExposedPorts": {"${PORT}/tcp": {"HostPort": "${PORT}"}}, "HostConfig": {"Binds": ["/usr/src/app/strategies/${BOT_ID}.js:/usr/src/app/strategies/${BOT_ID}.js"], "NetworkMode": "titan_backend"}, "PortBindings": { "${PORT}/tcp": [{ "HostPort": "${PORT}" }] }, "Env": ["BOTNAME=${BOT_ID}","PORT=${PORT}"], "Cmd": ["yarn", "start"]}\' -X POST http:/v1.24/containers/create?name=${BOT_ID}`

How ever its not correctly binding the volume

"Binds": ["/usr/src/app/strategies/${BOT_ID}.js:/usr/src/app/strategies/${BOT_ID}.js"]

Any idea how to properly bind a volume through the docker 1.24 api

lucas rodriguez
  • 980
  • 2
  • 8
  • 20
  • I don't fully understand how you're trying to do this but, isn't one problem that you're not getting shell substitution for `${BOT_ID}`? What happens if you replace the single quote (`'`) with double- and escaped double-quotes (`"`, `\"`)? – DazWilkin May 09 '20 at 18:21
  • And, does this need to be an `eval(...)`? Is it not possible to run the `curl` command directly? I think using `eval` compounds the variable substitution problem (if that's a problem). – DazWilkin May 09 '20 at 18:22
  • This is getting executed directly from a js api yes it has to be `eval` The shell is getting substituted. The question is around whether there is an alternative to `Binds` and how to use the alternative – lucas rodriguez May 09 '20 at 18:27
  • What language is this in? Can you use a [native Docker SDK](https://docs.docker.com/engine/api/sdk/), or failing that, a language-native HTTP client? – David Maze May 09 '20 at 21:23
  • This is what kind of what I was looking for: https://stackoverflow.com/questions/55845723/volume-bind-mounting-from-docker-in-docker but specific to using the doker api instead of the cli – lucas rodriguez May 09 '20 at 22:45

0 Answers0