获取docker compose运行起来对应的容器
(ctx context.Context, cli *client.Client, workingDir string, dockerComposeServices []string)
| 46 | |
| 47 | // 获取docker compose运行起来对应的容器 |
| 48 | func GetLocalContainersWithServices(ctx context.Context, cli *client.Client, |
| 49 | workingDir string, dockerComposeServices []string) []DockerComposeContainer { |
| 50 | |
| 51 | var dockerComposeContainers []DockerComposeContainer // result define |
| 52 | |
| 53 | // home dir |
| 54 | if workingDir[0:1] == "~" { |
| 55 | homeDir, _ := os.UserHomeDir() |
| 56 | workingDir = filepath.Join(homeDir, workingDir[1:]) |
| 57 | } |
| 58 | |
| 59 | //通过cli客户端对象去执行ContainerList(其实docker ps 不就是一个docker正在运行容器的一个list嘛) |
| 60 | containers, err2 := cli.ContainerList(ctx, types.ContainerListOptions{}) |
| 61 | common.CheckError(err2) |
| 62 | dockerComposeContainers = convertOriginContainer(containers, workingDir, dockerComposeServices) |
| 63 | |
| 64 | // 打印 |
| 65 | PrintDockerComposeContainers(dockerComposeContainers) |
| 66 | |
| 67 | return dockerComposeContainers |
| 68 | } |
| 69 | |
| 70 | // 检测远程服务器的环境,是否安装docker、docker-compose、git |
| 71 | func GetRemoteContainersWithServices(sshRemote common.SSHRemote, |
no test coverage detected