You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it possible to add attach function to fig? #423
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.
Maybe it's more convenient to use alias below in your terminal.
alias attach='bash -c "nsenter --mount --uts --ipc --net --pid --target docker inspect --format \"{{.State.Pid}}\" \$0"'
Then you can use attach container_name to enter a container.
@bcheng049 the docker-enter script also handles some edge-cases (e.g. If you're not using bash as your shell), and makes sure to set up the environment variables of the container and not your host environment. The alias you're suggesting, won't handle those.
Just wanted to clear that up to prevent people trying to solve problems that are already solved in the docker-enter script. Adding this functionality to fig would be a nice addition though (still hoping Docker itself will support this natively).
In the short run, I'd really advice people that want to have it now to install jpetazzo's script. Installing it is just a one-liner as explained in the readme; https://github.com/jpetazzo/nsenter
After installing, entering a running container is just simply docker-enter [container-name]
There's two issues here: 1) being able to enter with nsenter and fiddle around with a running container, and 2) a way to get docker run web bash behavior but also bring up the entire stack not just direct links. The first is great for debugging and the second is great for development workflows with volumes mounted into containers. Just bringing up links is not enough for many stacks.
I think fig up -d, fig run solves 2, but I'm not really clear on why you'd need to bring up services if they aren't linked. A container doesn't need to be running to share volumes.
The set up I have in mind is proxy -> web -> db. I'd like to be able to bring this stack up, but develop in web using a bash prompt. I haven't found an easy to to do this, such that all the links work.
I agree that fig attach and fig exec, analogous to their docker counterparts, would be good to have. Is anyone here asking for anything other than those?
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: truestdin_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.
Reacted by Ryan McNulty, Michael Wilson, Danilo F, Gabe Kopley, Carlos Feliciano Barba, Anees Iqbal, Fran Martinez, Tyrone, Patrick Berkeley, Timofey Martynov and 22 more
Reacted by Scott Weldon, Atsushi Yamamoto, Stanley Sathler, Matheus, Brandt Lareau and Paulo Felipe Souza
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).
Reacted by Gaugau, Alberto Harres and hirokihokari
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 #423 (comment)
Reacted by Gabe Kopley, Carlos Feliciano Barba and Scott Weldon
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.
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 #3106 (comment) - it's apparently tty that's triggering the timeout and missing timestamps in docker-compose logs.
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)
Reacted by Diana Eromosele Robinson, adansuku and Daniel Múnera Sánchez
Activity
shuron commentedon Aug 31, 2014
Need it too!
marksteve commentedon Aug 31, 2014
docker-enter(https://github.com/jpetazzo/nsenter/blob/master/docker-enter) is just a bash script.I supposed you can base on that to write a
fig-enterscript.0xcb49 commentedon Aug 31, 2014
Maybe it's more convenient to use alias below in your terminal.
alias attach='bash -c "nsenter --mount --uts --ipc --net --pid --target
docker inspect --format \"{{.State.Pid}}\" \$0"'Then you can use
attach container_nameto enter a container.dnephin commentedon Aug 31, 2014
It shouldn't be too difficult to add this using
dockerpty, which is what fig is using right now to handlefig run, I think.thaJeztah commentedon Aug 31, 2014
@bcheng049 the
docker-enterscript also handles some edge-cases (e.g. If you're not using bash as your shell), and makes sure to set up the environment variables of the container and not your host environment. The alias you're suggesting, won't handle those.erickbrower commentedon Aug 31, 2014
This would be huge for my team also
0xcb49 commentedon Aug 31, 2014
@thaJeztah Yes, it is just a snippet to avoid inputing many commands without installing a script.
thaJeztah commentedon Aug 31, 2014
Just wanted to clear that up to prevent people trying to solve problems that are already solved in the
docker-enterscript. Adding this functionality to fig would be a nice addition though (still hoping Docker itself will support this natively).In the short run, I'd really advice people that want to have it now to install jpetazzo's script. Installing it is just a one-liner as explained in the readme; https://github.com/jpetazzo/nsenter
After installing, entering a running container is just simply
docker-enter [container-name]tristanz commentedon Sep 11, 2014
There's two issues here: 1) being able to enter with
nsenterand fiddle around with a running container, and 2) a way to getdocker run web bashbehavior but also bring up the entire stack not just direct links. The first is great for debugging and the second is great for development workflows with volumes mounted into containers. Just bringing up links is not enough for many stacks.dnephin commentedon Sep 11, 2014
I think
fig up -d,fig runsolves 2, but I'm not really clear on why you'd need to bring up services if they aren't linked. A container doesn't need to be running to share volumes.tristanz commentedon Sep 11, 2014
The set up I have in mind is
proxy -> web -> db. I'd like to be able to bring this stack up, but develop in web using a bash prompt. I haven't found an easy to to do this, such that all the links work.robsonpeixoto commentedon Oct 31, 2014
attachandinteractiveis very useful to debug the running software using tools like python pdb.baptistedonaux commentedon Nov 13, 2014
It's an essential feature to configure docker container. When this feature are release ?
aanand commentedon Nov 13, 2014
I agree that
fig attachandfig exec, analogous to their docker counterparts, would be good to have. Is anyone here asking for anything other than those?12 remaining items
thomasf commentedon Sep 21, 2015
Just to help anyone looking here out I just found a simple solution that works for me.
docker-compose.ymlnow supports this:This also makes it possible to after the containers are up do
docker attach project_app_1which 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
attachfromdockerindocker-composewould also be nice but for me it isn't a requirement as long as the procedure is simple.cameron commentedon Sep 22, 2015
@thomasf to the rescue!
jaccarmac commentedon Feb 11, 2016
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.
kaiomagalhaes commentedon May 9, 2016
Thanks @thomasf, you made my day
gkop commentedon May 16, 2016
Curious, what is different between
docker-compose up <service>anddocker-compose up -d <service>followed bydocker 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).aanand commentedon May 17, 2016
'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 notifications@github.com wrote:
k2nr commentedon Jun 16, 2016
Because I also wanted to
attachto a runningrails serverprocess to communicate withbinding.pry, I am using the following simple script, which works well for me.Name it
docker-compose-attachand then rundocker-compose-attach <service>But I believe it's better for docker-compose to have
attachsubcommandgkop commentedon Jun 21, 2016
Our team has observed that while the config suggested by @thomasf does work nicely to permit interactive debugging of running containers,
tty: truecauses strange and unfortunate side effects when runningdocker-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 commentedon Jun 21, 2016
@dnephin I think what we're observing in first paragraph above ^^ might be an incident of #3106 (comment) - it's apparently
ttythat's triggering the timeout and missing timestamps in docker-compose logs.Should I create a separate issue for this?
/cc @thaJeztah
Merge pull request docker#423 from AkihiroSuda/list
shin- commentedon Feb 13, 2018
With #3106 fixed and
execandrunimplemented, I believe this can be closed. I don't think there's a scenario whereattachmakes a lot of sense (especially over the two other subcommands).JamesLivengood commentedon Jul 19, 2019
@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)