Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Piping docker run container ID to docker exec

In my development, I find myself issuing a docker run command followed by a docker exec command on the resulting container ID quite frequently. It's a little annoying to have to copy/paste the container ID between commands, so I was trying to pipe the container ID into my docker exec command.

Here's my example command.

docker run -itd image | xargs -i docker exec -it {} bash

This starts the container, but then I get the following error.

the input device is not a TTY

Does anyone have any idea how to get around this?

Edit: I also forgot to mention I have an ENTRYPOINT defined and cannot override that.

like image 818
jvhashe Avatar asked Dec 23 '22 17:12

jvhashe


1 Answers

Do this instead:

ID=$(docker run -itd image)  && docker exec -it $ID bash

Because xargs executes it arguments without allocating a new tty.

like image 81
Robert Avatar answered Dec 28 '22 09:12

Robert