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

DevOps

MOTOSHARE 🚗🏍️
Turning Idle Vehicles into Shared Rides & Earnings

From Idle to Income. From Parked to Purpose.
Earn by Sharing, Ride by Renting.
Where Owners Earn, Riders Move.
Owners Earn. Riders Move. Motoshare Connects.

With Motoshare, every parked vehicle finds a purpose. Owners earn. Renters ride.
🚀 Everyone wins.

Start Your Journey with Motoshare

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