docker / roadmap

Welcome to the Public Roadmap for All Things Docker! We welcome your ideas.
https://github.com/orgs/docker/projects/51
Creative Commons Zero v1.0 Universal
1.73k stars 251 forks source link

Using Docker Compose as a library #387

Open glours opened 2 years ago

glours commented 2 years ago

Tell us about your request Provide a stable Golang API for Docker Compose to let developers use Compose inside their own development without doing shell out.

Which service(s) is this request for? Docker Compose

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard? We have users asking if they can the cmd or pkg packages as a stable reference to embed Compose inside their own development. For now the answer is that we don't guarantee backward compatibility in Compose internals between 2 versions. We may consider to make interfaces present in pkg directory more stable and support an API usage of those interfaces.

Are you currently working around the issue? Not especially but the interfaces of Compose V2 are pretty stable now.

Additional context https://github.com/docker/compose/issues/9602 https://github.com/docker/compose/pull/9579

dockertopia commented 2 years ago

cc (me): @dockertopia so I can see this also in my PR queries.

shantanoo-desai commented 2 years ago

Description

An interesting requirement would be for Ansible.

Currently the community.docker is widely used Ansible Collection. It currently depends on Compose v1.x because Ansible Modules / Plugins generally depend on Python Libraries / APIs. Since v1.x is deprecated, and the compose v2 is a standalone Golang plugin, it becomes difficult to implement / update the collection.

Possible Solution

There is a possible solution python-on-whales which is generally just a Wrapper over the Docker CLI, as opposed to docker pip package which talks directly Docker Engine.

However, based on the discussion for the community.docker future roadmap it is still under consideration by the Maintainer. A possible exposed library / API would be a great help especially the current DevOps / IaaC landscape.

cc @felixfontein (maintainer of Ansible community.docker collection), might have some feedback here for community.docker for docker compose v2 roadmap

craph commented 1 year ago

Any updates on this subjects ?

felixfontein commented 8 months ago

Using Docker Compose as a library isn't useful for Ansible since Docker Compose isn't written in Python anymore, but in Go. But having a way to get machine readable output (see also https://github.com/docker/compose/issues/10872) for commands such as docker compose up, docker compose down, docker compose pull, docker compose stop, etc. would really help a lot. I've been looking at implementing support for Docker Compose v2 in Ansible modules during the last week and it has been a really frustrating experience, I constantly find new ways messages are written to stderr.

At least having a way to enable JSON stream output with some basic structure (that can easily be extended since it's JSON) would be extremely helpful to be able to use Docker Compose by shelling out.