Пример #1
0
func RunPods(file string) (RunOutput, error) {
	var out RunOutput
	p, err := config.Pods(file)
	if err != nil {
		return out, err
	}

	script, err := MakeCmd(p)
	if err != nil {
		return out, err
	}

	cmd := sh.Command{script}
	fmt.Println(file)
	fmt.Println(script)
	fmt.Println("=============================")
	out = RunOutput{
		Pid:         p.Id,
		Pods:        file,
		ContainerId: cmd.Ok(),
		// ContainerId: cmd.Mock()[0],
	}

	return out, nil
}
Пример #2
0
func InspectRunning(cid string) string {
	script := fmt.Sprintf("docker inspect --format='{{.State.Running}}' %s", cid)
	cmd := sh.Command{script}
	ret := cmd.Ok()
	if ret == "true" {
		return "YES"
	}
	return "NO"
}
Пример #3
0
func InspectPid(cid string) string {
	script := fmt.Sprintf("docker inspect --format='{{.Config.Labels.name}}' %s", cid)
	cmd := sh.Command{script}
	ret := cmd.Ok()
	if ret == "<no value>" {
		return ""
	}
	return ret
}
Пример #4
0
func TestRm(t *testing.T) {
	script := fmt.Sprintf("docker rm -f %s", busybox)
	cmd := sh.Command{script}
	t.Log(cmd.Ok())
}
Пример #5
0
package docker_test

import (
	"fmt"
	"testing"

	"github.com/lotreal/docker-pods/src/docker"
	"github.com/lotreal/docker-pods/src/sh"
)

var busybox = (func() string {
	cmd := sh.Command{"docker run -d -it busybox sh"}
	return cmd.Ok()[0:12]
})()

func TestInit(t *testing.T) {
	t.Logf("%s", docker.Ps())
	t.Logf("%s", busybox)
}

func TestIp(t *testing.T) {
	t.Log(docker.InspectIp(busybox))
}

func TestPort(t *testing.T) {
	t.Log(docker.InspectPorts(busybox))
}

func TestState(t *testing.T) {
	t.Log(docker.InspectPorts(busybox))
}
Пример #6
0
func InspectIp(cid string) string {
	script := fmt.Sprintf("docker inspect --format='{{.NetworkSettings.IPAddress}}' %s", cid)
	cmd := sh.Command{script}
	return cmd.Ok()
}
Пример #7
0
func InspectPorts(cid string) string {
	script := fmt.Sprintf("docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' %s", cid)
	cmd := sh.Command{script}
	ret := cmd.Ok()
	return ret
}