MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / convertOriginContainer

Function convertOriginContainer

cli/cmd/start/env.go:96–147  ·  view source on GitHub ↗

转换结构体

(containers []types.Container,
	workingDir string, dockerComposeServices []string)

Source from the content-addressed store, hash-verified

94
95// 转换结构体
96func convertOriginContainer(containers []types.Container,
97 workingDir string, dockerComposeServices []string) (dockerComposeContainers []DockerComposeContainer) {
98 for _, container := range containers {
99 currentServiceName := container.Labels["com.docker.compose.service"]
100 currentWorkingDir := container.Labels["com.docker.compose.project.working_dir"]
101 if workingDir != "" && currentWorkingDir != workingDir { // 工作目录不匹配
102 continue
103 }
104 if common.Contains(dockerComposeServices, currentServiceName) {
105 var ports []string
106 for _, port := range container.Ports {
107 if port.PublicPort <= 0 {
108 continue
109 }
110 str := fmt.Sprintf("%v:%v", port.PublicPort, port.PrivatePort)
111 if !common.Contains(ports, str) { // 限制重复的端口绑定信息
112 ports = append(ports, str)
113 }
114 }
115
116 // 去掉/
117 containerName := ""
118 for _, name := range container.Names {
119 tmp := ""
120 if strings.Index(name, "/") == 0 {
121 tmp = name[1:]
122 } else {
123 tmp = name
124 }
125 if len(containerName) > 0 {
126 containerName += "," + tmp
127 } else {
128 containerName += tmp
129 }
130 }
131
132 dockerComposeContainer := DockerComposeContainer{
133 ServiceName: currentServiceName,
134 ContainerName: containerName,
135 State: container.State,
136 Image: container.Image,
137 ImageID: container.ImageID,
138 Ports: ports,
139 }
140 dockerComposeContainers = append(dockerComposeContainers, dockerComposeContainer)
141 break
142 }
143
144 }
145
146 return dockerComposeContainers
147}
148
149// 打印 service 列表
150func PrintDockerComposeContainers(dockerComposeContainers []DockerComposeContainer) {

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected