Go Other
Permalink
Failed to load latest commit information.
testing testing: uploadToContainer don't need a running container Mar 14, 2017
travis-scripts travis-scripts: support new Docker package naming convention Feb 20, 2017
.gitignore Add dangling symlink to .gitignore Sep 7, 2015
.travis.yml travis: fix matrix specification Feb 17, 2017
AUTHORS authors: conceal user emails Feb 20, 2017
DOCKER-LICENSE update docker license url May 10, 2015
LICENSE Happy New Year Jan 4, 2017
Makefile Makefile: ignore context.Context error from golint Oct 14, 2016
README.markdown readme: check for errors on sample code Oct 25, 2016
appveyor.yml appveyor: use Go 1.7.5 Jan 28, 2017
auth.go add toml tags Feb 17, 2017
auth_test.go Fix vetshadow violations reported by gometalinter Sep 18, 2016
build_test.go tests: Fully specify ContextDir in build test Sep 19, 2016
change.go Update broken short links Oct 22, 2016
change_test.go client, test: small tweaks in imports Oct 15, 2015
client.go wrap stream reader instead of writers for inactivity timeout Feb 21, 2017
client_test.go client_test: use subtests to track test execution Feb 14, 2017
client_unix.go client_unix: support Dial and DialContext Feb 14, 2017
client_unix_test.go client: Tests run on both Windows and non-Windows Sep 19, 2016
client_windows.go client_windows: support DialContext Feb 14, 2017
client_windows_test.go client_windows_test: add space after buildtag Feb 14, 2017
container.go add toml tags Feb 17, 2017
container_test.go fix issues/625. Container inspect with IOPS limit. (update test) Feb 15, 2017
container_unix_test.go container: Separate Unix tests Sep 19, 2016
env.go env: fix golint warnings Aug 8, 2014
env_test.go make fmt, additional error checks May 10, 2015
event.go client: Add support for named pipe on Windows Sep 19, 2016
event_test.go Fix vetshadow violations reported by gometalinter Sep 18, 2016
example_test.go Fix example name (reported by vet) Sep 18, 2016
exec.go add toml tags Feb 17, 2017
exec_test.go Don't use constants that are not available on Go 1.5 Sep 19, 2016
image.go add support for cgroup parent on image build Mar 1, 2017
image_test.go add support for cgroup parent on image build Mar 1, 2017
integration_test.go integration_test: fix function call to use formatted output Apr 5, 2016
misc.go Update broken short links Oct 22, 2016
misc_test.go add RegistryConfig field to DockerInfo struct Oct 4, 2016
network.go add toml tags Feb 17, 2017
network_test.go network_test: fix test Sep 22, 2016
node.go Fix copyright headers Feb 1, 2017
node_test.go update import paths for docker dependencies Oct 4, 2016
service.go Add AuthConfigure to the CreateServiceOptions struct Mar 7, 2017
service_test.go Add AuthConfigure to the CreateServiceOptions struct Mar 7, 2017
signal.go container: provide some constants for signals on KillContainer Apr 27, 2014
swarm.go fix swarm related errors on 503 response from docker Mar 2, 2017
swarm_test.go fix swarm related errors on 503 response from docker Mar 2, 2017
tar.go Fix vetshadow violations reported by gometalinter Sep 18, 2016
task.go update import paths for docker dependencies Oct 4, 2016
task_test.go update import paths for docker dependencies Oct 4, 2016
tls.go tls: fix vet failure at tip Apr 23, 2016
volume.go small fix Feb 19, 2017
volume_test.go Don't use constants that are not available on Go 1.5 Sep 19, 2016

README.markdown

go-dockerclient

Travis Build Status AppVeyor Build Status GoDoc

This package presents a client for the Docker remote API. It also provides support for the extensions in the Swarm API. It currently supports the Docker API up to version 1.23.

This package also provides support for docker's network API, which is a simple passthrough to the libnetwork remote API. Note that docker's network API is only available in docker 1.8 and above, and only enabled in docker if DOCKER_EXPERIMENTAL is defined during the docker build process.

For more details, check the remote API documentation.

Example

package main

import (
	"fmt"

	"github.com/fsouza/go-dockerclient"
)

func main() {
	endpoint := "unix:///var/run/docker.sock"
	client, err := docker.NewClient(endpoint)
	if err != nil {
		panic(err)
	}
	imgs, err := client.ListImages(docker.ListImagesOptions{All: false})
	if err != nil {
		panic(err)
	}
	for _, img := range imgs {
		fmt.Println("ID: ", img.ID)
		fmt.Println("RepoTags: ", img.RepoTags)
		fmt.Println("Created: ", img.Created)
		fmt.Println("Size: ", img.Size)
		fmt.Println("VirtualSize: ", img.VirtualSize)
		fmt.Println("ParentId: ", img.ParentID)
	}
}

Using with TLS

In order to instantiate the client for a TLS-enabled daemon, you should use NewTLSClient, passing the endpoint and path for key and certificates as parameters.

package main

import (
	"fmt"

	"github.com/fsouza/go-dockerclient"
)

func main() {
	endpoint := "tcp://[ip]:[port]"
	path := os.Getenv("DOCKER_CERT_PATH")
	ca := fmt.Sprintf("%s/ca.pem", path)
	cert := fmt.Sprintf("%s/cert.pem", path)
	key := fmt.Sprintf("%s/key.pem", path)
	client, _ := docker.NewTLSClient(endpoint, cert, key, ca)
	// use client
}

If using docker-machine, or another application that exports environment variables DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH, you can use NewClientFromEnv.

package main

import (
	"fmt"

	"github.com/fsouza/go-dockerclient"
)

func main() {
	client, _ := docker.NewClientFromEnv()
	// use client
}

See the documentation for more details.

Developing

All development commands can be seen in the Makefile.

Commited code must pass:

Running make test will check all of these. If your editor does not automatically call gofmt -s, make fmt will format all go files in this repository.