Is it possible to add attach function to fig?
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.
@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 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, @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 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.
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 to the rescue!
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.
Thanks @thomasf, you made my day
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).
'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
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
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.
@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
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).
@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)