An issue when use hcs to implement "docker update" for HvContainer by Kathryn #931 pull request
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 694
- Forks
- 304
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 28
Description
Hi,dear friends.
I want to run "docker update" func for my Hyper-V containers to resize the memory and modify CPU settings, And the OS is Windows 10 20H2 with docker desktop. I cloned the branch ask_update_implementation hcsshim from your repo. and create a folder "update" in the root directory, write a code like the update_memory.
This code is like this:
`
package main
import (
"context"
"fmt"
hcsshim "github.com/Microsoft/hcsshim"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/internal/requesttype"
"github.com/Microsoft/hcsshim/internal/uvm"
"github.com/Microsoft/hcsshim/osversion"
"github.com/opencontainers/runtime-spec/specs-go"
)
const processorWeightMax = 10000
const bytesPerMB = 1024 * 1024
func GetContainers() ([]hcsshim.ContainerProperties, error){
owner := []string{"docker"}
query := hcsshim.ComputeSystemQuery{Owners: owner}
return hcsshim.GetContainers(query)
}
func ListAllContainers() bool{
// var props []hcsshim.ContainerProperties
props, err := GetContainers()
if err != nil{
fmt.Println("err is:%s", err)
}
props_len := len(props)
for i:=0; i<props_len; i++{
prop := props[i]
fmt.Println(prop.ID)
fmt.Println(prop.RuntimeImagePath)
fmt.Println(prop.SystemType)
container, err := OpenDockerContainer(prop.ID)
if err != nil{
fmt.Println(err)
}
UpdateWOCWMemory(prop.ID, 2048)
UpdateWOCWCPU(prop.ID, 30)
}
return true
}
func UpdateWOCWResource(ContainerID string, resourcePath string, settings interface{}) bool{
currentHCS, err := hcs.OpenComputeSystem(context.TODO(), ContainerID)
if err != nil {
fmt.Println("")
return false
}
var modification interface{}
modification = &hcsschema.ModifySettingRequest{
ResourcePath: resourcePath,
RequestType: requesttype.Update,
Settings: settings,
GuestRequest: nil,
}
modifyErr := currentHCS.Modify(context.TODO(), modification)
fmt.Println("Current HCS id is:%d", currentHCS.ID())
if modifyErr != nil{
fmt.Println("Something Wrong When modify")
fmt.Println(modifyErr)
}
return true
}
func UpdateWOCWMemory(ContainerID string, MemorySize uint64) bool{
var limit uint64 = 100
resources := &specs.WindowsResources{
Memory: &specs.WindowsMemoryResources{
Limit: &limit,
},
}
if resources.Memory != nil && resources.Memory.Limit != nil {
originMemorySizeInMB := *resources.Memory.Limit / bytesPerMB
fmt.Println(originMemorySizeInMB)
actualMB := (MemorySize + 1) &^ 1
fmt.Println(actualMB)
//memoryLimit := hcsoci.NormalizeMemorySize(context., ContainerID, originMemorySizeInMB)
return UpdateWOCWResource(ContainerID, resourcepaths.SiloMemoryResourcePath, actualMB)
}
return false
}
func UpdateWOCWCPU(ContainerID string, Maximum uint16) bool{
modification := &specs.WindowsCPUResources{
Count: nil,
Maximum: &Maximum,
Shares: nil,
}
return updateWCOWContainerCPU(ContainerID, modification)
}
func updateWCOWContainerCPU(ContainerID string, cpu *specs.WindowsCPUResources) bool {
// if host is 20h2+ then we can make a request directly to hcs
if osversion.Get().Build >= osversion.V20H2 {
fmt.Println("OS version is OK")
}
req := &hcsschema.Processor{}
if cpu.Count != nil {
procCount := int32(*cpu.Count)
req.Count = procCount
}
if cpu.Maximum != nil {
req.Maximum = int32(*cpu.Maximum)
}
if cpu.Shares != nil {
req.Weight = int32(*cpu.Shares)
}
return UpdateWOCWResource(ContainerID, resourcepaths.SiloProcessorResourcePath, req)
}
func OpenDockerContainer(ContainerID string) (hcsshim.Container, error){
return hcsshim.OpenContainer(ContainerID)
}
func main(){
ListAllContainers()
}
`
The source code file is here:
update_HvContainer.txt
The runing result like this image:

Because implement docker update for Hyper-V container is really important for my thesis. Can you give me a sample code that can be implemented for docker on Windows 10?
@dims @slonopotamus
Sorry to bother you, Wish you happy everyday!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the standalone update_HvContainer.txt example attached to the issue and review its HCS Modify calls for memory and CPU changes. The issue does not name a repository entry point or tests; completion would require a defined, reviewed approach for supporting docker update on Hyper-V containers, plus validation on the stated Windows environment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- infrastructure, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100