理解在Docker中运行命令后执行的代码

时间:2015-08-28 20:55:18

标签: docker

我刚刚在Docker doc中看到了下面的脚本。

root@aed84ee21bde:/opt/webapp# cat /etc/hosts 

执行运行cammand后发生了什么? ,下面的部分我的意思是:

func attributedStringFromDescription(description: String, withFontName fontName: String) -> NSAttributedString? {
    let attributedOptions : [String: AnyObject] = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
    let betterDescription = "<br><font face=\"\(fontName)\">" + description + "</font>"
    if let encodedData = betterDescription.dataUsingEncoding(NSUTF8StringEncoding) {
        return NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil)
    }
    return nil
}

有人可以逐行解释,我不明白。请这对我来说非常重要。

1 个答案:

答案 0 :(得分:1)

docker run -t -i --rm --link db:db training/webapp /bin/bash

此行在从图像/bin/bash创建的容器中执行命令training/webapp/bin/bash是一个交互式shell,因此执行它意味着您现在位于作为Docker容器的假机器内的shell中。 root@aed84ee21bde:/opt/webapp#是shell的提示符,表示您在主机rootaed84ee21bde,当前目录为/opt/webappcat /etc/hosts在容器外部表示同样的事情,除了在这里它指的是容器内的/etc/hosts文件,这可能与主系统上的文件不同。