https://github.com/iansmith/dockerclient
Docker client library in Go
https://github.com/iansmith/dockerclient
Last synced: 2 months ago
JSON representation
Docker client library in Go
- Host: GitHub
- URL: https://github.com/iansmith/dockerclient
- Owner: iansmith
- License: apache-2.0
- Fork: true (samalba/dockerclient)
- Created: 2014-07-28T22:32:04.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-07-24T21:39:03.000Z (over 11 years ago)
- Last Synced: 2024-06-21T12:57:35.285Z (almost 2 years ago)
- Homepage: http://www.docker.com/
- Size: 521 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Docker client library in Go
===========================
[](http://godoc.org/github.com/samalba/dockerclient)
This library supports few API calls but it will get extended over time.
Example:
```go
package main
import (
"github.com/samalba/dockerclient"
"log"
"time"
)
// Callback used to listen to Docker's events
func eventCallback(event *dockerclient.Event, args ...interface{}) {
log.Printf("Received event: %#v\n", *event)
}
func main() {
// Init the client
docker, _ := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)
// Get only running containers
containers, err := docker.ListContainers(false)
if err != nil {
log.Fatal(err)
}
for _, c := range containers {
log.Println(c.Id, c.Names)
}
// Inspect the first container returned
if len(containers) > 0 {
id := containers[0].Id
info, _ := docker.InspectContainer(id)
log.Println(info)
}
// Create a container
containerConfig := &dockerclient.ContainerConfig{Image: "ubuntu:12.04", Cmd: []string{"bash"}}
containerId, err := docker.CreateContainer(containerConfig)
if err != nil {
log.Fatal(err)
}
// Start the container
err = docker.StartContainer(containerId)
if err != nil {
log.Fatal(err)
}
// Stop the container (with 5 seconds timeout)
docker.StopContainer(containerId, 5)
// Listen to events
docker.StartMonitorEvents(eventCallback)
time.Sleep(3600 * time.Second)
}
```