-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
key sequence to detach from docker-compose up
#4560
Comments
I too would cast a vote in this direction. For example, to see that everything is starting up as expected I often do |
hi, did you find any solution? |
Actually, the key sequence is |
ctrl-z appears to work version 3 |
Woudln't ctrl-z stop the process? |
Ctrl+z stops the docker-compose process so the terminal is no more attached to any containers but they continue to run. Ctrl+p, Ctrl+q doesn’t work for me… Docker version 17.09.0-ce, build afdb6d4 |
@M4rotte docker-compose is weird. Thanks for explanation and tip! |
@M4rotte, Ctrl + Z puts the process to background. The process is no longer running, but is still using resources such (i.e. system memory). So i don't think it is a good idea to use ctr + z. |
@M4rotte I don't know why it doesn't work for you, however my linked question (to Stack Overflow) has 22 upvotes at the time of this post, while my comment here magically gained 3 downvotes. There's something clearly wrong, which is left as an exercise to the reader. |
@thiagowfx you are talking about docker, but we here talk about docker-compose, which is lacking the feature docker natively provides. |
Did you try to : I often do that when I forget to specify the '-d' switch with docker-compose up |
@MetaBarj0 and still you have |
@piranha79 yes, you are right: identical person. One is work, the other is private. |
simply putting the process to the background is no solution as streams stay attached in this case. I have some very chatty containers, so this is an issue. +1 for a "real" detach. |
Please consider adding this soon |
As a workaround, what I do is create an alias so I never forget: alias dcup="docker-compose up -d" |
I will cast an anti-vote here. Key sequences often conflict with custom settings with window managers like tmux and screen (including possible custom configurations), can clash with operating system hotkeys. I believe they're an anti-pattern for interfaces, even if Docker itself natively supports it. |
Perhaps a method to tell docker-compose to detach from another terminal? |
I am a little confused :) Docker supports the functionality so this isn't adding anything new -- it is just exposing functionality that already exists in the core tooling. If there is a feeling that this isn't a good approach wouldn't it make sense to look at removing it from docker itself rather than effectively breaking existing functionality? |
Considering this has gotten 105 upvotes at the time of this writing, I think the original thread's assertion that this isn't really well desired is... no longer accurate. Not having some way to detach once I've accidentally forgotten the -d, makes it EXTREMELY hard for me to even consider using docker-compose for anything other then basic testing. Even there I'm unlikely to use it because it then doesn't match how I deal with production. Even if I background the instance I've forgotten to do it in, and start an instance with it. when I come back to the first instance, shutting it down STILL kills all containers (even ones that it didn't start!). That makes it one of the most unforgiving commands in the UNIX world, only slightly less so then dd! |
CTRL-Z, then |
That still leaves the local process running, just not owned by the current shell. What we are asking for is a way to detach the remote instance and completely end the local process. |
Until a good solution is found for this I resorted to giving myself a safety net by adding this to my function docker-compose() {
if [ "$1" == "up" -a "$#" -eq 1 ]
then
echo "Are you sure you want to run 'dc up' without -d?"
echo "Run then:"
echo " command docker-compose up"
return 0
fi
command docker-compose "$@"
} |
I suggest that the default to be detached mode, and add the option to run in attached, or logging to a file. |
The nastiest thing is - if the containers are already running happily in background, an accidental Fix this already for crying out loud. |
@rustyx I agree wholeheartedly. As someone already mentioned above, this is one of the most unforgiving mistakes one can make while using docker-compose. Heck, probably one of the most in all of the Unix world. If at least one could send a USR1 signal or something to make it detach after realizing you've made a mistake, there would be a way out. |
Perhaps remove the attach feature completely and replace it with a printed note about running |
Ctrl-d would be a good key combination... not really because that's EOF and you're likely to accidentally close a shell in the target environment. CTRL-A or CTRL-B, like Screen or TMux use would be reasonable. You could have a family of commands, just as Screen or Tmux have the Ctrl-A or Ctrl-B + command key. |
why not use combination similar like "screen" does I sometimes want to run it attached for debugging purposes, and then detach later and leave it running in background. |
Is there an echo here? |
You can close a lot of programs with EOT (ex: cut) which is not closing the shell. Of course, you can close the shell with EOT too, but you can pay attention to not close it accidentally; also if you close it, you could open another terminal and continue your work after the docker-compose should run detached after EOT. |
I've found sending an explicit I like to avoid From an implementation end whenever the magic hotkey is decided upon having the sequence send |
I can confirm that @tylerszabo's suggestion of |
would it be possible to have |
@dpacmittal I am using your function, thanks for sharing. It has a little flaw though: if a container in your docker compose contains "up" in its name it will append "-d" to whatever command you execute except if your name contains "-d" in which case it will never append -d not even when the up command is used. to fix this, simply add spaces before and after the strings you compare int he two if conditions:
and in the countPosition function you also need to make sure that the grep statement only is true if the entire string matches:
i won't paste the entire script here, maybe you can just edit your command and apply this fix to keep things organized :) |
You can simply press ^Z, then SIGKILL the docker-compose process ( |
I'm using |
For Mac: |
I just wanted to close my session when it told me: "There are stopped jobs.", because I thought just sending them to the background with |
|
I came here, as others, looking for a way to be able to detach from a I have a unique solution that I thought I'd share. First, start the containers either by doing Now, do the |
I can't think of a reason why |
@dm17 i like the current attach default (if we had a detach key sequence) because detaching is something you can do instantly but starting a stack might take time. |
Why is this there no official solution for this? |
Works as a charm! Thank you very much! ✨ Outputs It's worth to mention that the
Versions:
OS: |
There really should be a way to make this happen with a control-key combination or Example, |
Is there a historical reason that docker-compose doesn't detach by default? I find it hard to think of a time I've ever wanted it to be attached instead of setting it to detach and then just using |
This is a good question and it's been asked before. It was also suggested back in 2018 that the default be detached. However, if that becomes the default, we still need a solution to detach from attached mode. |
For anyone still fighting with muscle memory. Here's a short addition to docker-compose() {
if [ "$1" = "up" ] && [ "$2" != "-d" ]; then
echo "Refusing to run docker-compose up without -d"
else
/usr/bin/docker-compose "$@"
fi
} |
Just in case, Is it Bash? You might like a single condition then like: Related: |
stupid... why not? |
just add an option to NOT shut down the project when using ctrl C |
this feature is very needed by alot of people |
When I realized this issue I just started behaving as if |
no longer works with this |
ctrl-p ctrl-q no longer works with w Enable Watch |
this has been topic in #291, however i want to make aware of this feature request a little more .
i vote for a key-sequence that you can use to detach from
docker-compose up
without stopping all containers (i.e. when you forgot to pass-d
). There seems to be a key-sequence for attached docker-containers (Ctrl-p
Ctrl-c
). It seems plausible to reuse this in docker-compose.The text was updated successfully, but these errors were encountered: