# Docker attach with command

**URL:** <https://forums.docker.com/t/docker-attach-with-command/134962>\
**Category:** Docker Desktop\
**Tags:** docker\
**Created:** [March 6, 2023, 3:54pm UTC](https://forums.docker.com/t/docker-attach-with-command/134962 "2023-03-06T15:54:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![uzer123](https://avatars.discourse-cdn.com/v4/letter/u/838e76/32.png) [@uzer123](https://forums.docker.com/u/uzer123)\
**Post date:** [March 6, 2023, 3:54pm UTC](https://forums.docker.com/t/docker-attach-with-command/134962/1 "2023-03-06T15:54:32Z")

</div>

i do `docker run -dit -w /project --name test espressif/idf`  
and then  
`docker attach test`  
and `idf.py build`  
Can i do something like:  
`echo "idf.py build" | docker attach test`?  
I dont want to use `docker exec test idf.py build`, as espressif/idf run a long entrypoint script that i want to avoid re-running in every new docker exec terminal…

---

<div class="post-metadata">

**Author:** ![terpz](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/terpz/32/36125_2.png) [@terpz](https://forums.docker.com/u/terpz)\
**Post date:** [March 6, 2023, 8:05pm UTC](https://forums.docker.com/t/docker-attach-with-command/134962/2 "2023-03-06T20:05:15Z")

</div>

Is there a reason why you just dont build the application in the image?  
so you dont have to run it everytime when you create a new instance?

---

<div class="post-metadata">

**Author:** ![uzer123](https://avatars.discourse-cdn.com/v4/letter/u/838e76/32.png) [@uzer123](https://forums.docker.com/u/uzer123)\
**Post date:** [March 7, 2023, 9:55am UTC](https://forums.docker.com/t/docker-attach-with-command/134962/3 "2023-03-07T09:55:38Z")

</div>

i have a script running in the host, and i dont want to go inside container’s terminal.  
Let’s say this is myscript.bat (running in windows cmd), if i do `docker attach` i have this problem:

```auto
# myscript.bat
echo "show stuff in host's terminal"
docker run -dit -w /project --name test espressif/idf
docker attach test
# now my script will not run idf.py build as a new terminal will open
root@CONTAINER:/project#

```

i was thinking something like:

```auto
# myscript.bat
echo "show stuff in host's terminal"
docker run -dit -w /project --name test espressif/idf
# script just continues
echo "idf.py build" | docker attach test
# do other stuff with the same script

```
