我很好奇,是否有一种方法可以查看正在运行的Windows容器使用的磁盘空间,以及该容器映像的组成部分。基本上,容器自创建以来“增长了”多少。
在Linux(或在HyperV中运行的Linux容器)中,该名称为docker ps -s
,但是该命令未在Windows容器上实现。我也尝试了docker system df -v
,但是也没有实现。也许通过直接查看磁盘上的某物或某物有一种骇人听闻的方法?
答案 0 :(得分:1)
我正在将docker用于Windows(docker桌面2.0.0.3),实际上已经实现了docker ps -s
。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
81acb264aa0f httpd "httpd-foreground" 6 minutes ago Up 6 minutes 80/tcp httpd 2B (virtual 132MB)
适用于Windows的Docker在MobyLinuxVM上运行。您可以访问VM和docker目录:
docker run --privileged -it -v /var/run/docker.sock:/var/run/docker.sock jongallant/ubuntu-docker-client
root@8b58d2fbe186:/# docker run --net=host --ipc=host --uts=host --pid=host –it --security-opt=seccomp=unconfined --privileged --rm -v /:/host alpine /bin/sh
root@8b58d2fbe186:/# chroot /host
现在,您可以像在Linux上一样访问/var/lib/docker
中的docker文件夹并检查大小。
答案 1 :(得分:1)
我在运行非HyperV(进程隔离)容器的Windows 10 1809上进行了检查,我非常确定它与Windows Server容器相同。
数据似乎保存在:
class CostingsViewController: UIViewController {
// MARK: Outlets
@IBOutlet weak var quantityLabel: UILabel!
@IBOutlet weak var priceTextField: UITextField!
@IBOutlet weak var markUpTextField: UITextField!
@IBOutlet weak var totalLabel: UILabel!
// MARK: Model objects
var quantity: Int? { didSet { updateTotal() } }
var price: Decimal? { didSet { updateTotal() } }
var markUp: Decimal? { didSet { updateTotal() } }
var total: Decimal? { didSet { totalLabel.text = priceFormatter.string(for: total) } }
// MARK: Private formatters
private var priceFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.minimumFractionDigits = 2
formatter.maximumFractionDigits = 2
formatter.generatesDecimalNumbers = true
return formatter
}()
private var quantityFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.minimumFractionDigits = 0
formatter.maximumFractionDigits = 0
return formatter
}()
private var percentFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .percent
formatter.minimumFractionDigits = 0
formatter.maximumFractionDigits = 2
formatter.generatesDecimalNumbers = true
return formatter
}()
override func viewDidLoad() {
super.viewDidLoad()
// I'm going to set these here, but maybe these were supplied by the presenting view controller
quantity = 3
price = Decimal(1000)
markUp = Decimal(0)
// update the UI controls
quantityLabel.text = quantityFormatter.string(for: quantity)
priceTextField.text = priceFormatter.string(for: price)
markUpTextField.text = percentFormatter.string(for: markUp)
totalLabel.text = priceFormatter.string(for: total)
}
}
private extension CostingsViewController {
private func updateTotal() {
// calculate total
let quant = Decimal(quantity ?? 0)
let cost = price ?? Decimal(0)
let percent = markUp ?? Decimal(0)
var unrounded = quant * cost * (percent + Decimal(1))
// round the result
var rounded = Decimal()
NSDecimalRound(&rounded, &unrounded, 2, .bankers)
// update our model
total = rounded
}
}
extension CostingsViewController: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// some useful constants
let decimalSeparator = priceFormatter.decimalSeparator ?? "."
let percentSymbol = percentFormatter.percentSymbol ?? "%"
// figure out what the string value will be after replacing the characters
let oldText = textField.text ?? ""
let updateRange = Range(range, in: oldText)!
let text = oldText.replacingCharacters(in: updateRange, with: string).filter(("01234567890" + decimalSeparator).contains)
// update the appropriate model object
switch textField {
case priceTextField:
if text == "" {
price = Decimal(0)
return true
} else if let value = priceFormatter.number(from: text)?.decimalValue {
price = value
return true
} else {
return false
}
case markUpTextField:
if text == "" {
markUp = Decimal(0)
return true
} else if let value = percentFormatter.number(from: text + percentSymbol)?.decimalValue {
markUp = value
return true
} else {
return false
}
default:
return true
}
}
func textFieldDidEndEditing(_ textField: UITextField) {
switch textField {
case priceTextField: textField.text = priceFormatter.string(for: price)
case markUpTextField: textField.text = percentFormatter.string(for: markUp)
default: break
}
}
}
在C:\ProgramData\Docker\windowsfilter\{ContainerId}
下的docker inspect {Id}
中有直接引用的文件夹。
该文件夹包含文件GraphDriver\Data\dir
,该文件似乎是每个容器的“可写层”。
我无法打开它并查看文件系统,但是如果我在容器中写入一些数据,我可以强制文件增长:
sandbox.vhdx
停止/重新启动容器后,该层将保留,并且 docker exec <Id> powershell get-childitem c:\ -recurse `> c:\windows\temp\test.txt
版本的容器将删除文件夹。
在研究过程中,我看到一个open PR in moby可以改善此文件夹的清理。