I am running a container with docker run --name cont -dt img
. As I understand this provides the container with a tty but will not attach stdout, stderr and stdin of my host terminal to the container which is also running in the background.
Now I thought that if I did docker attach cont
(docker documentation says it attaches stdio to a running container, attach) I would obtain the same effect (by running first docker logs cont
to see the stdout before the prompt) as running docker run --name cont -it img
(display stdout/sterr allocate a tty and connect the stdin to the container). However my host terminal attaches but just hangs and ctrl+c
must be used to detach (ctrl+p+q
will not work).
I'd like to understand why attach
does not work like I intend it? I mean the true logic behind it and how you came to understand this if possible, I know that running cont
with the option -dit
and reattaching works. If anybody has tips or can point to some reading sources to understand this it would help a lot. Thanks!
Dockerfile
FROM ubuntu:latest
RUN apt update -y
COPY . /tmp
WORKDIR /tmp
CMD ["/tmp/app.sh"]
app.sh
#!/bin/sh
echo "Enter your name: "
read name
echo "Hello ${name}!"