What is Docker attach?

Viewed 37268

I am very new to Docker and I have been able to understand 4 things

  • Dockerfile
  • Docker image
  • Docker container
  • docker-compose

along with some basic commands like docker run, docker log etc.

Now, I came across this command docker attach with a description here

Use docker attach to attach to a running container using the container’s ID or name, either to view its ongoing output or to control it interactively. You can attach to the same contained process multiple times simultaneously, screen sharing style, or quickly view the progress of your detached process.`

I have no idea what do they mean when they say we can attach if we want to view a container's ongoing activity or output? If I have a Container for a console application and I simply do docker run on it then I can see the output right there in the console window.

What could be a few benefits of docker attach?

3 Answers

What is Docker attach?

Allows one terminal to attach a running container. It allows you to connect to process' STDIO in another terminal.

What's the benefit?

Docs:

This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.

Here's a demo of attach:

enter image description here

Docker attach command is used to attach our terminal to a running container to control I/O operations.

Related