Attach Attachment Container
Attach can only be used for interactive containers, not for background containers, when we start an interactive container with Docker start or Docker restart, the container is interactive but the container does not have a terminal associated with it. This allows the attach command interaction container to be associated with a terminal.
First, give some of the columns.
Docker run-it--name=ubuntu ubuntu:14.04/bin/sh
This startup runs the/bin/sh command to create a terminal associated with the container.
After exit, the container becomes a exited state
Docker start Ubuntu startup container but no associated terminals
Docker PS can see that the container is already running
Docker attach Ubuntu associates the container with the terminal when it was created.
Note that there is a need to click the carriage return to display the Terminal View container log
Just said a bit about the interactive container, but the background container, there is no interaction, how do we look at its information, you can see through the log.
First we create a background container
Docker run-d--name daemon_logs ubuntu/bin/bash-c ' for ((i=0;1;i++));d O-echo $i; sleep 1;done; ' Let the container enter an incremented number every second
After creation, we cannot see the output because it is a background container.
Docker PS View container information
Docker logs Daemon_logs view container logs
-F: To view live logs
-T: Indicates the date on which the log was generated
–tail=n: To see the n log from the tail