mirror of https://github.com/docker/docs.git
godep: update dockerclient.
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
f49fc12ff3
commit
1a82c9ce7d
|
|
@ -60,7 +60,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/samalba/dockerclient",
|
||||
"Rev": "8b9427265e82fddde577648b986fbe78d816b333"
|
||||
"Rev": "5e5020b90dd4657c33d446356556481182d2d66b"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/samuel/go-zookeeper/zk",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ Docker client library in Go
|
|||
|
||||
Well maintained docker client library.
|
||||
|
||||
Example:
|
||||
# How to use it?
|
||||
|
||||
Here is an example showing how to use it:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
|
@ -25,7 +27,7 @@ func main() {
|
|||
docker, _ := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)
|
||||
|
||||
// Get only running containers
|
||||
containers, err := docker.ListContainers(false)
|
||||
containers, err := docker.ListContainers(false, false, "")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
@ -41,14 +43,19 @@ func main() {
|
|||
}
|
||||
|
||||
// Create a container
|
||||
containerConfig := &dockerclient.ContainerConfig{Image: "ubuntu:12.04", Cmd: []string{"bash"}}
|
||||
containerId, err := docker.CreateContainer(containerConfig)
|
||||
containerConfig := &dockerclient.ContainerConfig{
|
||||
Image: "ubuntu:14.04",
|
||||
Cmd: []string{"bash"},
|
||||
AttachStdin: true,
|
||||
Tty: true}
|
||||
containerId, err := docker.CreateContainer(containerConfig, "foobar")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Start the container
|
||||
err = docker.StartContainer(containerId)
|
||||
hostConfig := &dockerclient.HostConfig{}
|
||||
err = docker.StartContainer(containerId, hostConfig)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
@ -58,6 +65,19 @@ func main() {
|
|||
|
||||
// Listen to events
|
||||
docker.StartMonitorEvents(eventCallback, nil)
|
||||
|
||||
// Hold the execution to look at the events coming
|
||||
time.Sleep(3600 * time.Second)
|
||||
}
|
||||
```
|
||||
|
||||
# Maintainers
|
||||
|
||||
List of people you can ping for feedback on Pull Requests or any questions.
|
||||
|
||||
- [Sam Alba](https://github.com/samalba)
|
||||
- [Michael Crosby](https://github.com/crosbymichael)
|
||||
- [Andrea Luzzardi](https://github.com/aluzzardi)
|
||||
- [Victor Vieux](https://github.com/vieux)
|
||||
- [Evan Hazlett](https://github.com/ehazlett)
|
||||
- [Donald Huang](https://github.com/donhcd)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,25 @@ func NewDockerClientTimeout(daemonUrl string, tlsConfig *tls.Config, timeout tim
|
|||
|
||||
func (client *DockerClient) doRequest(method string, path string, body []byte, headers map[string]string) ([]byte, error) {
|
||||
b := bytes.NewBuffer(body)
|
||||
req, err := http.NewRequest(method, client.URL.String()+path, b)
|
||||
|
||||
reader, err := client.doStreamRequest(method, path, b, headers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer reader.Close()
|
||||
data, err := ioutil.ReadAll(reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (client *DockerClient) doStreamRequest(method string, path string, in io.Reader, headers map[string]string) (io.ReadCloser, error) {
|
||||
if (method == "POST" || method == "PUT") && in == nil {
|
||||
in = bytes.NewReader(nil)
|
||||
}
|
||||
req, err := http.NewRequest(method, client.URL.String()+path, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -83,18 +101,19 @@ func (client *DockerClient) doRequest(method string, path string, body []byte, h
|
|||
}
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode == 404 {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
if resp.StatusCode >= 400 {
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, Error{StatusCode: resp.StatusCode, Status: resp.Status, msg: string(data)}
|
||||
}
|
||||
return data, nil
|
||||
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
func (client *DockerClient) Info() (*Info, error) {
|
||||
|
|
@ -464,3 +483,25 @@ func (client *DockerClient) RenameContainer(oldName string, newName string) erro
|
|||
_, err := client.doRequest("POST", uri, nil, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (client *DockerClient) ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error) {
|
||||
var fromSrc string
|
||||
v := &url.Values{}
|
||||
if source == "" {
|
||||
fromSrc = "-"
|
||||
} else {
|
||||
fromSrc = source
|
||||
}
|
||||
|
||||
v.Set("fromSrc", fromSrc)
|
||||
v.Set("repo", repository)
|
||||
if tag != "" {
|
||||
v.Set("tag", tag)
|
||||
}
|
||||
|
||||
var in io.Reader
|
||||
if fromSrc == "-" {
|
||||
in = tar
|
||||
}
|
||||
return client.doStreamRequest("POST", "/images/create?"+v.Encode(), in, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,5 @@ type Client interface {
|
|||
PauseContainer(name string) error
|
||||
UnpauseContainer(name string) error
|
||||
RenameContainer(oldName string, newName string) error
|
||||
ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,3 +135,8 @@ func (client *MockClient) RenameContainer(oldName string, newName string) error
|
|||
args := client.Mock.Called(oldName, newName)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (client *MockClient) ImportImage(source string, repository string, tag string, tar io.Reader) (io.ReadCloser, error) {
|
||||
args := client.Mock.Called(source, repository, tag, tar)
|
||||
return args.Get(0).(io.ReadCloser), args.Error(1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ type HostConfig struct {
|
|||
SecurityOpt []string
|
||||
NetworkMode string
|
||||
RestartPolicy RestartPolicy
|
||||
Ulimits []Ulimit
|
||||
LogConfig LogConfig
|
||||
}
|
||||
|
||||
type ExecConfig struct {
|
||||
|
|
@ -88,8 +90,11 @@ type ContainerInfo struct {
|
|||
Running bool
|
||||
Paused bool
|
||||
Restarting bool
|
||||
OOMKilled bool
|
||||
Dead bool
|
||||
Pid int
|
||||
ExitCode int
|
||||
Error string // contains last known error when starting the container
|
||||
StartedAt time.Time
|
||||
FinishedAt time.Time
|
||||
Ghost bool
|
||||
|
|
@ -256,3 +261,14 @@ type Stats struct {
|
|||
MemoryStats MemoryStats `json:"memory_stats,omitempty"`
|
||||
BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
|
||||
}
|
||||
|
||||
type Ulimit struct {
|
||||
Name string `json:"name"`
|
||||
Soft uint64 `json:"soft"`
|
||||
Hard uint64 `json:"hard"`
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
Type string `json:"type"`
|
||||
Config map[string]string `json:"config"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue