compose icon indicating copy to clipboard operation
compose copied to clipboard

Is it possible to add attach function to fig?

Open 0xcb49 opened this issue 12 years ago • 35 comments

For example, Using command "fig attach appname" to enter the container which was created by fig. I think this may be helpful in some cases. Now I know that nsenter can attach a new bash shell on a running container, but I don't know if it's possible to intergrate it with fig. Thanks.

0xcb49 avatar Aug 19 '14 07:08 0xcb49

@aanand even if it doesn't make sense in the context of fig up to have an "interactive" container/s, would it be reasonable to allow a service to allocate a pseudo-TTY, i.e. to have a fig.yml key which has the same effect as docker cli's run -t flag?

michaelsbradleyjr avatar Dec 23 '14 12:12 michaelsbradleyjr

@michaelsbradleyjr that might make some sense, in that there have been reports of software that complains if it can't find a tty.

Still, I'm worried that such an option might confuse people into thinking that fig up will be interactive. Maybe if it's called pseudo_tty, that won't be an issue.

aanand avatar Dec 23 '14 17:12 aanand

@aanand, @michaelsbradleyjr, I second that. When I do fig up, I can't get an erlang shell on a remote node. I have to do 'fig run' and then something like this works:

$ docker exec -it foo_web_run_1 erl -remsh '[email protected]'

I'd like to be able to get the repl even in production environment.

koddo avatar Feb 18 '15 18:02 koddo

@koddo I've been doing something similar. By the way, there's a tty-related bug in docker exec:

https://github.com/docker/docker/issues/8755

The documentation and help output don't mention it, and it can be tricky to figure out what's going on if you don't' think to check the output of the tty command. Anyway, I just wanted to give you a heads up in case you weren't aware of the bug.

michaelsbradleyjr avatar Feb 18 '15 18:02 michaelsbradleyjr

Just to help anyone looking here out I just found a simple solution that works for me.

docker-compose.yml now supports this:

app:
  tty: true
  stdin_open: true

This also makes it possible to after the containers are up do docker attach project_app_1 which seems to work fine.

I have no idea when this started getting possible but it works for me using docker 1.8.2 and docker-compose 1.3.3. Very thankful for this, it has been my major turnoff for developing using compose and python with pdb.

Just wanted to make this clear because I did not get that it was this easy at all by reading this issue conversation.

Mirroring the attach from docker in docker-compose would also be nice but for me it isn't a requirement as long as the procedure is simple.

thomasf avatar Sep 21 '15 14:09 thomasf

@thomasf to the rescue!

cameron avatar Sep 22 '15 06:09 cameron

tty: true
stdin_open: true

does not work for me. It may be because I'm on Windows, or it may be a bug in a newer version of Compose. I'm on 1.6.0.

jaccarmac avatar Feb 11 '16 15:02 jaccarmac

Thanks @thomasf, you made my day

kaiomagalhaes avatar May 09 '16 20:05 kaiomagalhaes

Curious, what is different between docker-compose up <service> and docker-compose up -d <service> followed by docker attach <service-instance> that @thomasf' solution for interactive debugging works with the latter but not with the former? (using pry, with the former, execution stops, but standard input doesn't seem to make it to the container).

gkop avatar May 16 '16 23:05 gkop

'up' does not hook up the terminal stdin. It's not designed for interactive use, because it usually operates on multiple containers.

On Tue, 17 May 2016 at 00:02 Gabe Kopley [email protected] wrote:

Curious, what is different between docker-compose up and docker-compose up -d followed by docker attach that @thomasf https://github.com/thomasf' solution for interactive debugging works with the latter but not with the former? (using pry, with the former, execution stops, but standard input doesn't seem to make it to the container).

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/docker/compose/issues/423#issuecomment-219574002

aanand avatar May 17 '16 10:05 aanand

Because I also wanted to attach to a running rails server process to communicate with binding.pry, I am using the following simple script, which works well for me.

#!/usr/bin/env bash
docker attach $(docker-compose ps -q $1)

Name it docker-compose-attach and then run docker-compose-attach <service>

But I believe it's better for docker-compose to have attach subcommand

k2nr avatar Jun 16 '16 03:06 k2nr

Our team has observed that while the config suggested by @thomasf does work nicely to permit interactive debugging of running containers, tty: true causes strange and unfortunate side effects when running docker-compose logs: the timestamps are missing from the logs and we get disconnected after 1 minute.

@k2nr first of all, thank you for the alias - it is certainly handy for myself and my team, as attach is a viable workaround in the face of the issue with the logs ^^ . I don't think however it belongs as a proper subcommand to docker-compose because it assumes that you only have one docker instance of the service running, which is not realistic in many cases.

gkop avatar Jun 21 '16 00:06 gkop

@dnephin I think what we're observing in first paragraph above ^^ might be an incident of https://github.com/docker/compose/issues/3106#issuecomment-196508170 - it's apparently tty that's triggering the timeout and missing timestamps in docker-compose logs.

Should I create a separate issue for this?

/cc @thaJeztah

gkop avatar Jun 21 '16 17:06 gkop

With #3106 fixed and exec and run implemented, I believe this can be closed. I don't think there's a scenario where attach makes a lot of sense (especially over the two other subcommands).

shin- avatar Feb 13 '18 00:02 shin-

@thomasf That worked for me to get into a debugger, but it doesn't let me type anything - like typing in c, or n to continue through doesn't work (I have to ctrl + C and close the server to get out of it)

JamesLivengood avatar Jul 19 '19 20:07 JamesLivengood