community.docker icon indicating copy to clipboard operation
community.docker copied to clipboard

Feature Request: Exec functionality for docker_compose module

Open ryanmerolle opened this issue 3 years ago • 9 comments

Currently, I do not see a way to interrace with containers leveraging the exec command. It would be great if this was natively supported by this docker collection.

ryanmerolle avatar Mar 08 '21 14:03 ryanmerolle

@ryanmerolle the connection plugins (community.docker.docker and community.docker.docker_api) both allow to run commands in Docker containers via exec.

I guess you're interested in something like the ansible.builtin.command module for Docker containers?

felixfontein avatar Mar 09 '21 06:03 felixfontein

I was using this with a gitlab runner and did not have a collection built into my ansible container. I can just bake the collection into my container. I was totally not even thinking about the community docker collection, but ha I raised my request in said repo. I am happy to close this honestly.

ryanmerolle avatar Mar 11 '21 02:03 ryanmerolle

@ryanmerolle I've created a PR for an exec module in #105, feel free to test it out (or review it)!

felixfontein avatar Mar 16 '21 12:03 felixfontein

@felixfontein I apologize for forgetting about this. The module works perfectly for my needs and is much appreciated. Would it be challenging to also extend to docker-compose exec? That would allow me to get rid of the last of my ansible.builtin.shell modules for docker-compose exec.

Again I appreciate the PR you provided. Thanks!

ryanmerolle avatar Aug 20 '21 01:08 ryanmerolle

@felixfontein I apologize for forgetting about this. The module works perfectly for my needs and is much appreciated.

Thanks!

Would it be challenging to also extend to docker-compose exec?

I think so, but I'm not sure. docker-compose is a separate (Python) program on top of Docker itself, so there's no way to control it with with Docker daemon. The docker_compose module basically hooks into docker-compose (since it's Python) and makes it do the things it wants. I guess that emulating docker-compose exec will require a similar approach to find out the actual container ID. In any case, I'm not very familiar with docker-compose (I also don't use it), maybe it's simpler to do...

felixfontein avatar Aug 20 '21 11:08 felixfontein

I reopened this and adjusted the title, maybe someone else is interested in working on this :)

felixfontein avatar Aug 20 '21 11:08 felixfontein

As written above, the hard part here is figuring out the correct container ID. Everything else can be done as in the docker_container_exec module (I guess we can move some more stuff from it into module_utils to reduce duplicate code).

felixfontein avatar Aug 20 '21 11:08 felixfontein

Yeah, it seems like initializing a compose project and inserting this, this, and this from docker-compose into this section of the docker_contatiner_exec module will transform it into a docker_compose_exec module.

Ajpantuso avatar Aug 20 '21 12:08 Ajpantuso

Any movement on this, would love to have this functionality

efourd avatar Oct 19 '23 19:10 efourd