supervisor icon indicating copy to clipboard operation
supervisor copied to clipboard

Migrate from dockerpy to aiodocker

Open mdegat01 opened this issue 3 months ago • 5 comments

Description

Dockerpy is not asyncio friendly, a bit of a hassle to use and no longer actively maintained as the Docker team does not use python for docker compose anymore.

Aiodocker is asyncio friendly, still a bit of a hassle to use but is actively maintained by a new group.

We should migrate to the latter and begin contributing to it in order to improve the experience. Because we need a good docker client library in Supervisor, its a big part of what we do.

Additional context

No response

mdegat01 avatar Oct 10 '25 21:10 mdegat01

Hi @mdegat01, thank you for your contribution!

Task issues are restricted to Open Home Foundation staff and authorized contributors.

If you would like to:

If you believe you should have access to create Task issues, please contact the maintainers.

github-actions[bot] avatar Oct 10 '25 21:10 github-actions[bot]

Going to start to collect a running list of things I've found as I go through API by API.

Differences of note:

  • images.get is equivalent images.inspect in aiodocker. In Dockerpy we received an Image object with the inspect details in attrs and some other common fields mapped into properties (id, tags, etc.)
  • images.list in aiodocker pushes all kwargs directly to the GET images/json API. This makes it far less friendly to use then Dockerpy's images.list that accepted a few common params like name and handled making the query string json for you. This code is a reference for how that works.
  • images.delete in aiodocker = images.remove in dockerpy
  • containers are very different from images. containers.get and containers.list return a DockerContainer instance. Unlike with dockerpy this instance does not have the inspect data, its only field is id. You must use DockerContainer.show to get the inspect info which is a coroutine and makes another API call to docker.
  • aiodocker has even less definition for exceptions then dockerpy. For instance to determine if an image or container is "Not Found" you catch the generic aiodocker.exceptions.DockerError and check if err.status == 404. Compare to dockerpy which raises docker.errors.NotFound
  • To tag an image, you use images.tag and just pass the image id as the first parameter. Whereas dockerpy did that for you since Image instances had a tag method. It's otherwise identical
  • aiodocker's images.import_image functions identically to dockerpy's images.load in terms of inputs, it wants a binary stream of the tarball although aiodocker has a stream function to presumably tell us about images as they load. They differ massively in output. Dockerpy nicely parses the log of the output to give us Image objects as shown here. We need this so we'll have to recreate for aiodocker, it simply gives us that log.

mdegat01 avatar Oct 10 '25 21:10 mdegat01

Running list of PRs we will need for aiodocker:

  • There is no equivalent to docker info in aiodocker. They only have an equivalent to docker version and we need more info then that provides
  • ~~images.pull does not support providing a platform in aiodocker. We cannot use it right now~~ Actually its in there. Somehow I missed it 🙈

mdegat01 avatar Oct 10 '25 21:10 mdegat01

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Nov 23 '25 19:11 github-actions[bot]

Check default timeout to be in similar ball-park to dockerpy (specifically when adding events).

Maybe also add timeout parameter to the import_image command. See also https://github.com/home-assistant/supervisor/pull/6391#issuecomment-3608791369.

agners avatar Dec 03 '25 20:12 agners