Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support docker exec command #593

Closed
k4nar opened this issue Oct 28, 2014 · 78 comments

Comments

Projects
None yet
@k4nar
Copy link

commented Oct 28, 2014

I've just learned about the new docker exec command. Wouldn't it be great to add it to fig ?

I think it really makes sense with fig, as you could run fig up and then exec some commands (like a shell) to debug your running containers if something happen.
Of course this is already possible by running docker exec -it your_container cmd, but I think that it wouldn't hurt to have fig exec service cmd.

I'll try to give it a shot and submit a PR.

@bfirsh

This comment has been minimized.

Copy link
Contributor

commented Oct 28, 2014

@k4nar

This comment has been minimized.

Copy link
Author

commented Oct 29, 2014

I think we'll have to wait for docker/docker-py#363 to land.

@imsickofmaps

This comment has been minimized.

Copy link

commented Oct 30, 2014

Just an FYI as I clicked through this link, docker/docker-py#363 has landed

@dnephin dnephin added the enhancement label Nov 9, 2014

@k4nar

This comment has been minimized.

Copy link
Author

commented Nov 13, 2014

I'm working on it. I have something working for simple commands, like fig exec web echo "Hello World!", but I don't know yet how to make it works with applications using TTYs.
I'm looking at dockerpty but I think it will require some modifications, as for now it only handles the client.start method.
If anyone with more experience than me on the subject wants to help it's welcome :) . You can reach me here or on IRC.

@pikeas

This comment has been minimized.

Copy link

commented Dec 14, 2014

+1!

@Stono

This comment has been minimized.

Copy link

commented Dec 15, 2014

+1

2 similar comments
@andradei

This comment has been minimized.

Copy link

commented Dec 28, 2014

👍

@hadim

This comment has been minimized.

Copy link

commented Jan 17, 2015

+1

@hadim

This comment has been minimized.

Copy link

commented Jan 17, 2015

It would also be nice to be able to define exec command in fig.yml.

@baptistedonaux

This comment has been minimized.

Copy link

commented Jan 18, 2015

+1 Yes I would it !

@Grokzen

This comment has been minimized.

Copy link

commented Feb 9, 2015

+1

1 similar comment
@jhftrifork

This comment has been minimized.

Copy link

commented Feb 11, 2015

+1

@dnephin

This comment has been minimized.

Copy link
Contributor

commented Feb 11, 2015

docker exec is already "supported" by the docker cli

docker exec <container name>

This really wouldn't change with docker-compose, you'd just use the service name instead of the container name. It doesn't seem to me like exec is really a feature of composition. In the same way that docker-compose doesn't duplicate docker inspect or docker import. Those are very much operations for individual containers, so they don't really need to exist in compose.

@Vrakfall

This comment has been minimized.

Copy link

commented Feb 11, 2015

+1

Well I think this would be a usage improvement. It implies shorter commands (= more user friendly) and less pain when it comes to using long container names. As some fig commands like kill or rm are already doing the same job than docker while shortening the command lines, why not implement it for commands like exec or inspect (e.g.).

It would, personally, ease my repetitive tasks. (Because you know, at work, you can't always have the choice of the paths or directories names.)

@dnephin

This comment has been minimized.

Copy link
Contributor

commented Feb 11, 2015

In the case of kill or rm at least they are "group" operations, in that you can run them on every container in the composition. This is not the case for exec.

I suspect, in the long term, that eventually the docker cli will start to understand docker-compose.yml and be able to support service names (this was the case in some of the earlier proposals for compose). Although that may still be a long way off.

It seems like there are already a lot of ways of dealing with long names that it doesn't really need to be part of compose. You can always use an environment variable (export PRJT="verylongdockercomposeprojectname"; docker exec $PRJT_service_1) or a bash alias, or a bash script. You can even use tab completion with docker.

@Vrakfall

This comment has been minimized.

Copy link

commented Feb 11, 2015

You're right, I didn't see it like that.

Well, I'm still thinking about some magic that could do "fig exec". You said something about grouping. What if it would actually be able to group the exec command and be able to run a magic cat or tail -f in all the services (e.g. to add some logs to the console prompt). Another use case could be to run a automated script put in every container (e.g. a sanity check .sh or some daily checks) in one command. It could be neat, combined to a bash script that would e.g. call it everyday.

This is an idea I juste had. What do you think about it ?
(I personally don't need it in a close future.)

@aanand

This comment has been minimized.

Copy link
Contributor

commented Feb 11, 2015

I'm in favour of supporting commands like exec and inspect - their docker equivalents aren't hellish, but it's a pain having to type out the full container name - and once we switch to using labels, container names will be a lot less predictable.

@thedug

This comment has been minimized.

Copy link

commented Feb 11, 2015

+1

I'm often:

  1. running fig ps to get list of container names,
  2. running docker exec -it container

It would be nice to have a command that worked like fig run but didn't start a new container

@k4nar

This comment has been minimized.

Copy link
Author

commented Feb 12, 2015

@aanand @dnephin : Next week I'll have some time to work on this. Last time I checked I was stuck at using dockerpty with an exec command.

@NodeGuy

This comment has been minimized.

Copy link

commented Feb 16, 2015

I'm trying to use docker exec in a script and, as far as I can tell, I can't know the container name in advance because fig generates it automagically. That's why we need fig exec.

Ah, I just figured out that I can do this:

docker exec $(fig ps -q service) command

@dnephin

This comment has been minimized.

Copy link
Contributor

commented Feb 16, 2015

You don't have to use the hex id, you can use the name <project>_<service>_1. You know the service name, and the project name can either be set (using $FIG_PROJECT_NAME or -p) or you can assume the default.

@NodeGuy

This comment has been minimized.

Copy link

commented Feb 16, 2015

The last time I checked manually, the name was <project>_<service>_4. How can I know the final digit?

@dnephin

This comment has been minimized.

Copy link
Contributor

commented Feb 16, 2015

Ah, normally it will be _1, if you're seeing it use higher numbers it means you're either using fig scale, or there are old containers sticking around using the lower numbers. I forget exactly the condition that causes this, but if you docker rm__xall the containers with earlier numbers, you should see it using_1` consistently.

@mikehaertl

This comment has been minimized.

Copy link

commented Feb 16, 2015

+1

Actually I thought, that's what fig run would already do and was surprised to find out, that it will always run the command in a new container instead.

@lcamacho

This comment has been minimized.

Copy link

commented Feb 19, 2015

+1

1 similar comment
@schmunk42

This comment has been minimized.

Copy link
Contributor

commented Mar 2, 2015

+1

@chiedo

This comment has been minimized.

Copy link

commented Mar 5, 2015

I agree with @mikehaertl. What would be great would be to be able to run a command like the following:

docker-compose exec [name of service] command

As apposed to having to do the following :

docker exec [container name] command

@pawelkaczor

This comment has been minimized.

Copy link

commented Jan 17, 2016

+1

3 similar comments
@Neschur

This comment has been minimized.

Copy link

commented Jan 18, 2016

+1

@Ehekatl

This comment has been minimized.

Copy link

commented Jan 20, 2016

+1

@stupied4ever

This comment has been minimized.

Copy link

commented Jan 26, 2016

+1

@michabbb

This comment has been minimized.

Copy link

commented Jan 26, 2016

just a note about this +1 thing:

since github doesn´t care about real needs for features like +1, it´s sad, but there are alternatives

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 9, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 10, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 11, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 11, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 11, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
@qcho

This comment has been minimized.

Copy link

commented Feb 12, 2016

+1 Waiting for exec to be part of compose! :D

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 15, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 15, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 16, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 17, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
@docteurklein

This comment has been minimized.

Copy link

commented Feb 18, 2016

Just a quick note about a zsh function I declared in my ~/.zshenv:

dce() { docker exec -it "${COMPOSE_PROJECT_NAME}_${1}_1" ${@:2} }

It's usable like that:

dce <service-name> bash

You'll need to export COMPOSE_PROJECT_NAME for that.

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 19, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
@ptahchiev

This comment has been minimized.

Copy link

commented Feb 19, 2016

+1 ..I need to create solr indexes after the server is up:

docker exec -it nemesis-solr bin/solr create_core -c products

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 22, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 22, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>

TomasTomecek added a commit to TomasTomecek/compose that referenced this issue Feb 29, 2016

implement exec
Resolves docker#593

Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
@michaelarnauts

This comment has been minimized.

Copy link

commented Feb 29, 2016

One-liner to the rescue:

docker exec -it $(docker-compose ps | grep <service> | cut -d" " -f 1) <command>
@krasi-georgiev

This comment has been minimized.

Copy link

commented Feb 29, 2016

Yeah right , like you will ever remember that when you need it :)

@michaelarnauts

This comment has been minimized.

Copy link

commented Feb 29, 2016

No need to remember it. I have all my test/deployment statements in one handy Makefile.

@aanand aanand closed this in #2023 Feb 29, 2016

@roytruelove

This comment has been minimized.

Copy link

commented Oct 4, 2016

@aanand can you comment on the reason for closing this one? I see workarounds in the thread but no 'won't fix'es

@docteurklein

This comment has been minimized.

Copy link

commented Oct 5, 2016

@roytruelove it's implemented since Feb 29, as stated by by aanand in PR 2023.

@thesobercoder

This comment has been minimized.

Copy link

commented Apr 30, 2018

+1 Much needed.

@thaJeztah

This comment has been minimized.

Copy link
Member

commented May 1, 2018

@thesobercoder did you actually read the comments directly before yours? This was implemented over two years ago; #2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.