4. What is the difference between docker exec and attach?

DevOps

YOUR COSMETIC CARE STARTS HERE

Find the Best Cosmetic Hospitals

Trusted • Curated • Easy

Looking for the right place for a cosmetic procedure? Explore top cosmetic hospitals in one place and choose with confidence.

“Small steps lead to big changes — today is a perfect day to begin.”

Explore Cosmetic Hospitals Compare hospitals, services & options quickly.

✓ Shortlist providers • ✓ Review options • ✓ Take the next step with confidence

Docker attach
This command to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name. attach the running container with the following command. you need to press enter once execute the below command, docker is waiting for your input.

docker attach nodeapi

once attached, you can do all the cli commands like you can check the node version, run the bundle file, exit etc..

But the problem here once you exit out of this, your container is no logger in the up status. your container is also in exit status.

Docker exec
The docker exec command runs a new command in a running container. execute the below command after restarting container nodeapi in the above command.

// start the container
docker start nodeapi
// execute the exec command
docker exec -it nodeapi bash

you can exit now and if you list the containers now we can see container is still running.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x