增加 docker 可以在 Container Optimized OS 中访问的磁盘大小
Increasing the disk size that docker can access in Container Optimized OS
我正在尝试 运行 一个简单的每日批处理脚本,该脚本可以 运行 几个小时,之后它将发送它生成的数据并关闭实例。为此,我将以下内容放入 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 引擎中用完磁盘 space。
关于如何增加 docker 服务可用的卷大小有什么想法吗?
Docker引擎使用实例磁盘的space。所以如果容器没有 space 是因为 Instance 的磁盘已满。
您可以尝试做的第一件事是创建一个具有更大磁盘的实例。 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
我正在尝试 运行 一个简单的每日批处理脚本,该脚本可以 运行 几个小时,之后它将发送它生成的数据并关闭实例。为此,我将以下内容放入 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 引擎中用完磁盘 space。
关于如何增加 docker 服务可用的卷大小有什么想法吗?
Docker引擎使用实例磁盘的space。所以如果容器没有 space 是因为 Instance 的磁盘已满。
您可以尝试做的第一件事是创建一个具有更大磁盘的实例。 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