Skip to content

Is it possible to add attach function to fig? #423

Closed

Description

@0xcb49

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.

Activity

  1. shuron commented on Aug 31, 2014

    @shuron

    Need it too!

  2. marksteve commented on Aug 31, 2014

    @marksteve

    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-enter script.

  3. 0xcb49 commented on Aug 31, 2014

    @0xcb49
    Author

    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.

  4. dnephin commented on Aug 31, 2014

    @dnephin

    It shouldn't be too difficult to add this using dockerpty, which is what fig is using right now to handle fig run, I think.

  5. thaJeztah commented on Aug 31, 2014

    @thaJeztah
    Member

    @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.

  6. erickbrower commented on Aug 31, 2014

    @erickbrower

    This would be huge for my team also

  7. 0xcb49 commented on Aug 31, 2014

    @0xcb49
    Author

    @thaJeztah Yes, it is just a snippet to avoid inputing many commands without installing a script.

  8. thaJeztah commented on Aug 31, 2014

    @thaJeztah
    Member

    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]

  9. tristanz commented on Sep 11, 2014

    @tristanz

    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.

  10. dnephin commented on Sep 11, 2014

    @dnephin

    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.

  11. tristanz commented on Sep 11, 2014

    @tristanz

    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.

  12. robsonpeixoto commented on Oct 31, 2014

    @robsonpeixoto

    attach and interactive is very useful to debug the running software using tools like python pdb.

  13. baptistedonaux commented on Nov 13, 2014

    @baptistedonaux

    It's an essential feature to configure docker container. When this feature are release ?

  14. aanand commented on Nov 13, 2014

    @aanand

    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?

  15. 12 remaining items

  16. thomasf commented on Sep 21, 2015

    @thomasf

    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.

  17. cameron commented on Sep 22, 2015

    @cameron

    @thomasf to the rescue!

  18. jaccarmac commented on Feb 11, 2016

    @jaccarmac
    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.

  19. kaiomagalhaes commented on May 9, 2016

    @kaiomagalhaes

    Thanks @thomasf, you made my day

  20. gkop commented on May 16, 2016

    @gkop

    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).

  21. aanand commented on May 17, 2016

    @aanand

    '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:

    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)

  22. k2nr commented on Jun 16, 2016

    @k2nr

    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

  23. gkop commented on Jun 21, 2016

    @gkop

    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.

  24. gkop commented on Jun 21, 2016

    @gkop

    @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.

    Should I create a separate issue for this?

    /cc @thaJeztah

  25. added a commit that references this issue on Jan 19, 2017
  26. shin- commented on Feb 13, 2018

    @shin-

    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).

  27. JamesLivengood commented on Jul 19, 2019

    @JamesLivengood

    @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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions