mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-10-05 09:53:21 +08:00
Return swarm info to be displayed in the FE
This requires that PWD is working as a container in the same network as all dinds Add icons to swarmInfo
This commit is contained in:
@@ -4,6 +4,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
@@ -40,6 +43,22 @@ func GetContainerInfo(id string) (types.ContainerJSON, error) {
|
||||
return c.ContainerInspect(context.Background(), id)
|
||||
}
|
||||
|
||||
func GetDaemonInfo(host string) (types.Info, error) {
|
||||
transport := &http.Transport{
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 1 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext}
|
||||
cli := &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
c, err := client.NewClient(host, client.DefaultVersion, cli, nil)
|
||||
if err != nil {
|
||||
return types.Info{}, err
|
||||
}
|
||||
return c.Info(context.Background())
|
||||
}
|
||||
|
||||
func CreateNetwork(name string) error {
|
||||
opts := types.NetworkCreate{Driver: "overlay", Attachable: true}
|
||||
_, err := c.NetworkCreate(context.Background(), name, opts)
|
||||
|
Reference in New Issue
Block a user