Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

add run command #45

Closed
wants to merge 1 commit into from
Closed

add run command #45

wants to merge 1 commit into from

Conversation

brancz
Copy link
Contributor

@brancz brancz commented Sep 2, 2015

Mimicking the docker-compose run command in form of

$ libcompose <service> <command>

Signed-off-by: Frederic Branczyk [email protected]

@aanand
Copy link
Contributor

aanand commented Sep 3, 2015

We should reuse the docker client's code for attaching to containers, rather than re-implementing it - it's a really complex process.

@brancz
Copy link
Contributor Author

brancz commented Sep 3, 2015

I agree. Maybe I'll take a look at the docker client once I have some more time on my hand, for now we'll just keep it line by line.

@brancz brancz force-pushed the run-command branch 2 times, most recently from d72e8de to 04bae5c Compare September 8, 2015 19:35
@brancz
Copy link
Contributor Author

brancz commented Sep 8, 2015

I revised all my commits and squashed them. Now the only thing I would like to improve is to really attach the container instead of just printing the log output. As @aanand mentioned, I'm going to try and reuse docker client code for this.

@brancz
Copy link
Contributor Author

brancz commented Sep 9, 2015

@aanand Do you think it would make sense to essentially instantiate the docker cli and call the attach command?

@aanand
Copy link
Contributor

aanand commented Sep 9, 2015

@flower-pot Yeah, essentially, though instantiating a CLI object is going to be ugly.

It might be worth trying to extract that code so it's more reusable and submitting it as a PR to docker/docker.

@brancz
Copy link
Contributor Author

brancz commented Sep 10, 2015

I agree. I'm going to take a look at how we can do that. The thing is, the attach command heavily relies on the hijack function which is only accessible for the cli object and package internal. And come to think about it, instantiating the cli object is really bad, since we also have to handle all settings like TLS and everything. The problem we have here is really that the docker cli is not built to be used as a library, right? Maybe the attach functionality should be added to samalba/dockerclient? (it seems like a previous attempt has failed samalba/dockerclient#3 and looks pretty complicated) To be honest, I'm really unsure on which path to continue; help appreciated 😄

@ibuildthecloud
Copy link
Contributor

@flower-pot I agree the CLI functionality should be pulled out. It would nice if we could find out what the status of moby/moby#15188 is. Basically there was supposed to be an effort to refactor a lot of the CLI code.

I've been down this path before with other projects I've written and agree that instantiating the docker CLI is a nightmare. I think the correct first steps would be to figure out how to refactor the code in docker/docker to put the attach logic we need into a reusable pkg. It's just all the dirty TTY handling that we need. It can probably be encapsulated pretty well.

@brancz
Copy link
Contributor Author

brancz commented Sep 14, 2015

Do you think the core team is going to take care of that? It seems pretty time consuming and I'm probably not the right guy to tackle this as I'm not very familiar with the docker codebase.

joshwget added a commit to joshwget/libcompose that referenced this pull request Sep 17, 2015
@brancz brancz force-pushed the run-command branch 2 times, most recently from 0f7763e to e75a461 Compare October 23, 2015 11:41
mimicing the docker-compose run command in form of

$ libcompose <service> <command>

Signed-off-by: Frederic Branczyk <[email protected]>
@brancz
Copy link
Contributor Author

brancz commented Oct 23, 2015

Alright ported to the new dockerclient and now using its attach functionality. What do you think? I'm not entirely sure how to test this though.

@vdemeester
Copy link
Collaborator

@flower-pot Sorry for the late review. Thanks for the PR, few consideration/comments :

  • docker-compose run supports more flags than this but I think it's good to focus on the main behavior and then the additionnal flags (I'll create an issue to keep track of diff between docker-compose and libcompose). We'll update the commands in PRs to follow.
  • By default docker-compose run start the container with stdin and a pseudo-terminal (something like -ti in the docker cli). This is not the case in this PR — when I do a libcompose-cli run myservice /bin/bash, I can't do anything in it.

I'll take a look at the code too 😉

@cpuguy83
Copy link

cpuguy83 commented Nov 6, 2015

Here is swarm's hijack implementation: https://github.com/docker/swarm/blob/894d1abd639eedb8234caf63fbc458a6791563bb/api/utils.go#L133

It's a bit cleaner.

@cpuguy83
Copy link

cpuguy83 commented Nov 6, 2015

It's a little different because it's proxying, but probably useful.

@brancz
Copy link
Contributor Author

brancz commented Nov 6, 2015

@vdemeester no problem, I haven't had time to revise it either. I think I had the problem that when opening stdin that the stream would never close therefore the execution never ended. But I have to take another look to make sure that's the case.

@vdemeester
Copy link
Collaborator

@flower-pot still willing (or having time) to work on that ?

@brancz
Copy link
Contributor Author

brancz commented Dec 25, 2015

I don't really have the time for it right now. If you don't want to use my changes you can close the PR.

@vdemeester
Copy link
Collaborator

@flower-pot ok, I'm gonna carry it then 😉, keeping your commit and iterate on it 👍

Thanks for the hard work so far, really appreciated 🎅

@brancz
Copy link
Contributor Author

brancz commented Dec 25, 2015

@vdemeester Glad I could help :)

@vdemeester vdemeester mentioned this pull request Dec 29, 2015
1 task
@vdemeester
Copy link
Collaborator

Carrying in #133.

@vdemeester vdemeester closed this Dec 29, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants