Why does "docker attach" hang?

I can run an ubuntu container successfully:

# docker run -it -d ubuntu
3aef6e642327ce7d19c7381eb145f3ad10291f1f2393af16a6327ee78d7c60bb
# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
3aef6e642327        ubuntu              "/bin/bash"         3 seconds ago       Up 2 seconds                            condescending_sammet

But executing docker attach hangs:

# docker attach 3aef6e642327

Until I press any key, such as Enter:

# docker attach 3aef6e642327
root@3aef6e642327:/#
root@3aef6e642327:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

Why does docker attach hang?

Update:

After reading the comments, I think I get the answers:

prerequisite:

"docker attach" reuse the same tty, not open new tty.

(1) Executing the docker run without daemon mode:

# docker run -it ubuntu
root@eb3c9d86d7a2:/# 

Everything is OK, then run ls command:

root@eb3c9d86d7a2:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@eb3c9d86d7a2:/#

(2) Run docker run in daemon mode:

# docker run -it -d ubuntu
91262536f7c9a3060641448120bda7af5ca812b0beb8f3c9fe72811a61db07fc

Actually, the following should have been outputted to stdout from the running container:

root@91262536f7c9:/#

So executing docker attach seems to hang, but actually it is waiting for your input:

# docker attach 91262536f7c9
ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@91262536f7c9:/#

Why Does He Do That?: Inside the Minds of Angry , Amazon.com: Why Does He Do That?: Inside the Minds of Angry and Controlling Men eBook: Bancroft, Lundy: Kindle Store. When you’re facing something you don’t want to do, it can make you feel tense. Putting off that dreaded chore is a way to get some short-term relief. The downside is that you’ll still have to tackle your task in the future, which may make you feel guilty or angry -- and cause your stress to rise more. If


I ran into this issue as well when attempting to attach to a container that was developed by someone else and already running a daemon. (In this case, it was LinuxServer's transmission docker image).

Problem:

What happened was the terminal appeared to 'hang', where typing anything didn't help and wouldn't show up. Only Ctrl-C would kick me back out.

docker run, docker start, docker attach all was not successful, turns out the command I needed (after the container has been started with run or start) was to execute bash, as chances are the container you pulled from doesn't have bash already running.

Solution:

docker exec -it <container-id> bash

(you can find the container-id from running docker ps -a).

This will pull you into the instance with a functional bash as root (assuming there was no other explicit set up done by the image you pulled).

I know the accepted answer has captured this as well, but decided to post another one that is a little more terse and obvious, as the solution didn't pop out for me when I was reading it.

Why does the coronavirus spread so easily between people?, Researchers have identified microscopic features that could make the pathogen more infectious than the SARS virus — and serve as drug  Another reason you may yawn is because the body wants to wake itself up. The motion helps stretch the lungs and their tissues, and it allows the body to flex its muscles and joints.


This happened to me once for the following reason:

It could be that the bash command inside the container is executing a "cat" command.

So when you attach to the container (the bash command) you are actualy inside the cat command which is expecting input. (text and/or ctrl-d to write the file)

Why does India have so few coronavirus/Covid-19 cases and deaths , India may have certain characteristics that protect it from the deadliest impact, but they do not suggest that it will escape the pandemic  Answers to why you get goosebumps, hiccups, eye twitches, ringing in your ears, and the feeling of the hair on your neck standing up. Share on Facebook: http


When I run docker attach container-name, then nothing output, even Ctrl-c is invalid. So, first try

docker attach container-name --sig-proxy=false

and then ctrl-c can stop it. Why it didn't output anything? just because the container doesn't output. Actually I need to enter my container and run some shell command. So the correct command is

docker exec -ti container-name bash

Why Does Covid-19 Make Some People So Sick? Ask Their DNA , James Hamblin: There are other diseases that can manifest in a wide variety of ways, but this one is unique in its unpredictability. What was  Why do some people fare so much worse than others? Here’s a clue: The recovering patient is a high school student, while the dead man was in late 50s and “medically high-risk,” according to


If you cannot access command line, just make sure you run your container with -i flag at start.

Listen: Why Do Some People Get Sicker?, The pandemic has hit Germany hard, with more than 100000 people infected. But the percentage of fatal cases has been remarkably low  Why do you Love me #CharlotteLawrence #WhyDoYouLoveMe. Category Music; Licensed to YouTube by AMRA, LatinAutor - SonyATV, UMPI, LatinAutor, Sony ATV Publishing, Abramus Digital, CMRRA, EMI Music


A German Exception? Why the Country's Coronavirus Death Rate Is , Is it a mirage, or has something really changed? It's not surprising that our online behavior would look somewhat different. The coronavirus has  There are also cultural reasons why China plays host to large outbreaks. "Many Chinese people, even city dwellers, insist that freshly slaughtered poultry is tastier and more healthful than refrigerated or frozen meat," journalist Melinda Liu wrote for Smithsonian in 2017.


Why does it suddenly feel like 1999 on the internet?, If you take the five largest countries in Western Europe - the UK, Germany, France, Italy and Spain - their combined population is roughly 320  Russian President Vladimir Putin said this week his country managed to stop the mass spread of coronavirus -- and that the situation was "under control," thanks to early and aggressive measures to


Coronavirus: Why are international comparisons difficult?, But why does he want to mine in space? And what are the benefits? Radio 1 Newsbeat has been speaking to a couple of experts who can fill us  Why We Ask. The 2020 Census is easy. The questions are simple. NAME. We ask for names to ensure everyone in the . house is counted. Listing the name of each person in the household helps respondents include all members, particularly in large house-holds where a respondent may forget who was counted and who was not. SEX