Docker attach: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Overview=
=Overview=


Attach local standard input, output, and error streams to a running container. The container to attach to should be started in [[Docker_run#-i.2C_--interactive|interactive mode]], giving the ability to type into it, and with a [[Docker_run#-t.2C_--tty|TTY]] so you can see the input and output:
Attaches the invoking shell's stdin, stdout and stderr to the container specified as argument.  


docker run -dit alpine1 alpine ash
The attachment will succeed only if the target container was started in [[Docker_Concepts#Interactive_Mode|interactive mode]]:


Then, the attachment can be performed later:
docker run [-d] '''-i''' alpine ash


  docker attach alpine1
Then, the attachment can then be performed with:
 
  docker attach <''container-id''>
 
Starting the container in [[Docker_Concepts#Detached_Mode|detached mode]] is optional, <tt>docker attach</tt> can attach to a non-detached container as well. In that case, two shells (the one from which [[docker run]] was executed and the one from which [[docker attach#Overview|docker attach]] was executed) will be attached at the same time to the container.

Latest revision as of 07:46, 3 May 2018

Internal

Overview

Attaches the invoking shell's stdin, stdout and stderr to the container specified as argument.

The attachment will succeed only if the target container was started in interactive mode:

docker run [-d] -i alpine ash

Then, the attachment can then be performed with:

docker attach <container-id>

Starting the container in detached mode is optional, docker attach can attach to a non-detached container as well. In that case, two shells (the one from which docker run was executed and the one from which docker attach was executed) will be attached at the same time to the container.