Difference between docker exec and docker attach

In this article, we explore the difference between docker attach and docker exec. Both docker attach and docker exec are used to explore the docker container.

Docker exec creates a new process in the container’s environment while docker attach just connects the standard input/output of the main process inside the container to corressponding standard input/output error of the current terminal.

Docker exec is used specifically for running new tasks or process in an already running or started container, be it a shell or some other process.

Difference between docker exec and docker attach

difference between docker attach and docker exec

In the above snap, we have used docker attach to access the running container on same standard input/output.

docker exec

In the above snap, we have used docker exec to access the container2

Conclusion:

Both docker exec and docker attach are used to connect or access the container but only difference is that docker exec creates a differrent process to access the container whereas docker attach connects to the same standard input/out or the same terminal. To explore more about docker components, please refer Docker documentation.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments