Docker Learning Notes (v) Attach and Logs command __docker

Source: Internet
Author: User
Tags docker ps docker run
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.