gpt4 book ai didi

docker - 增加Docker在Container Optimized OS中可以访问的磁盘大小

转载 作者:行者123 更新时间:2023-12-02 20:59:01 24 4
gpt4 key购买 nike

我试图运行一个简单的每日批处理脚本,该脚本可以运行几个小时,之后它将发送生成的数据并关闭实例。为此,我将以下内容放入user-data:

users:
- name: cloudservice
uid: 2000

runcmd:
- sudo HOME=/home/root docker-credential-gcr configure-docker
- |
sudo HOME=/home/root docker run \
--rm -u 2000 --name={service_name} {image_name} {command}
- shutdown

final_message: "machine took $UPTIME seconds to start"

我正在使用python脚本创建实例,以生成API的配置,如下所示:

def build_machine_configuration(
compute, name: str, project: str, zone: str, image: str
) -> Dict:

image_response = (
compute.images()
.getFromFamily(project="cos-cloud", family="cos-stable")
.execute()
)
source_disk_image = image_response["selfLink"]

machine_type = f"zones/{zone}/machineTypes/n1-standard-1"

# returns the cloud init from above
cloud_config = build_cloud_config(image)

config = {
"name": f"{name}",
"machineType": machine_type,
# Specify the boot disk and the image to use as a source.
"disks": [
{
"type": "PERSISTENT",
"boot": True,
"autoDelete": True,
"initializeParams": {"sourceImage": source_disk_image},
}
],
# Specify a network interface with NAT to access the public
# internet.
"networkInterfaces": [
{
"network": "global/networks/default",
"accessConfigs": [{"type": "ONE_TO_ONE_NAT", "name": "External NAT"}],
}
],
# Allow the instance to access cloud storage and logging.
"serviceAccounts": [
{
"email": "default",
"scopes": [
"https://www.googleapis.com/auth/devstorage.read_write",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/datastore",
"https://www.googleapis.com/auth/bigquery",
],
}
],
# Metadata is readable from the instance and allows you to
# pass configuration from deployment scripts to instances.
"metadata": {
"items": [
{
# Startup script is automatically executed by the
# instance upon startup.
"key": "user-data",
"value": cloud_config,
},
{"key": "google-monitoring-enabled", "value": True},
]
},
}
return config

但是,我的docker引擎内的磁盘空间不足。

关于如何增加可用于docker服务的卷的大小的任何想法?

最佳答案

Docker引擎使用实例磁盘的空间。因此,如果容器没有空间,是因为实例的磁盘已满。

您可以尝试做的第一件事是创建具有更大磁盘的实例。 The documentation说:

disks[ ].initializeParams.diskSizeGb string (int64 format)

Specifies the size of the disk in base-2 GB. The size must be at least 10 GB. If you specify a sourceImage, which is required for boot disks, the default size is the size of the sourceImage. If you do not specify a sourceImage, the default disk size is 500 GB.



您可以在部署中添加字段 diskSizeGb来增加大小:
"disks": [
{
[...]
"initializeParams": {
"diskSizeGb": 50,
[...]

您可以尝试的另一件事是在实例中执行以下命令,以查看磁盘是否已满以及哪个分区已满:
$ df -h

以相同的方式,您可以执行以下命令来查看 disk usage of the Docker Engine:
$ docker system df

The client and daemon API must both be at least 1.25 to use this command. Use the docker version command on the client to check your client and daemon API versions.



如果需要更多信息,可以使用标志-v
$ docker system df -v

关于docker - 增加Docker在Container Optimized OS中可以访问的磁盘大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61403495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com