# Dynamically convert the docker CLI commands to docker API packets

**URL:** <https://forums.docker.com/t/dynamically-convert-the-docker-cli-commands-to-docker-api-packets/137562>\
**Category:** General\
**Tags:** docker\
**Created:** [September 6, 2023, 2:11pm UTC](https://forums.docker.com/t/dynamically-convert-the-docker-cli-commands-to-docker-api-packets/137562 "2023-09-06T14:11:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![manatusz](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@manatusz](https://forums.docker.com/u/manatusz)\
**Post date:** [September 6, 2023, 2:11pm UTC](https://forums.docker.com/t/dynamically-convert-the-docker-cli-commands-to-docker-api-packets/137562/1 "2023-09-06T14:11:19Z")

</div>

I have the following problem:

I would like to send the docker engine the HTTP requests by myself and not with the docker CLI.  
Is there any way to dynamically convert the docker CLI commands to docker API packets without implementing a full parser by myself?

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/bluepuma77/32/32688_2.png) [@bluepuma77](https://forums.docker.com/u/bluepuma77)\
**Post date:** [September 6, 2023, 5:43pm UTC](https://forums.docker.com/t/dynamically-convert-the-docker-cli-commands-to-docker-api-packets/137562/2 "2023-09-06T17:43:55Z")

</div>

Check for libraries for your programming language, for NodeJS there is for example [GitHub - apocas/dockerode: Docker + Node = Dockerode (Node.js module for Docker's Remote API)](https://github.com/apocas/dockerode)

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [September 6, 2023, 7:15pm UTC](https://forums.docker.com/t/dynamically-convert-the-docker-cli-commands-to-docker-api-packets/137562/3 "2023-09-06T19:15:10Z")

</div>

> **[Develop with Docker Engine SDKs](https://docs.docker.com/engine/api/sdk/)**
>
> Using Docker SDKs to automate Docker tasks in your language of choice

---

<div class="post-metadata">

**Author:** ![manatusz](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@manatusz](https://forums.docker.com/u/manatusz)\
**Post date:** [September 7, 2023, 10:46am UTC](https://forums.docker.com/t/dynamically-convert-the-docker-cli-commands-to-docker-api-packets/137562/4 "2023-09-07T10:46:24Z")

</div>

I use Python and the [Docker SDK for Python](https://docker-py.readthedocs.io/en/stable/index.html) module. The idea is to implement a “wrapper” around the `docker run` CLI command. So the tool I’m working on could take the same input as the original `run` command would. To achieve this I implemented a parameter converter, which you can find [here](https://github.com/axem-solutions/dem/blob/e4be673ac4b163f9822c67a7adbdda5ce2c3a37e/dem/core/container_engine.py#L38C11-L38C11). Although this function only handles a very small subset of the possible parameters, which are sufficient for me at moment, later it would be nice to cover all the params. I guess the easiest solution would be to use the Docker CLI as a subprocess, but in the future, I would like to send commands to multiple remote Docker Engines simultaneously, which is quite difficult with the Docker CLI. Is there any (most optimally Python) lib that does the conversion for all supported parameters and keeps up to date with the API releases?

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [September 12, 2023, 5:30pm UTC](https://forums.docker.com/t/dynamically-convert-the-docker-cli-commands-to-docker-api-packets/137562/5 "2023-09-12T17:30:29Z")

</div>

> [@manatusz](#):
>
> I guess the easiest solution would be to use the Docker CLI as a subprocess, but in the future, I would like to send commands to multiple remote Docker Engines simultaneously,

If you are still looking for ideas, since you can change the endpoint by setting the environment variable “DOCKER\_HOST”, wouldn’t that be enough?

---

<div class="post-metadata">

**Author:** ![manatusz](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@manatusz](https://forums.docker.com/u/manatusz)\
**Post date:** [October 3, 2023, 12:13pm UTC](https://forums.docker.com/t/dynamically-convert-the-docker-cli-commands-to-docker-api-packets/137562/6 "2023-10-03T12:13:22Z")

</div>

Ákos, sorry for the late answer.  
I’m afraid that could lead to problems in the future. For example, the [DEM](https://github.com/axem-solutions/dem) (the tool in question) is working in the background, while the user tries to interact with the local Docker Engine using the CLI. Since the DOCKER\_HOST points to a remote host, the issues CLI command will be executed there.  
Now I try to use the context feature. I just started to dig into this topic, but I think it should solve the aforementioned problem.
