Go Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
internal Rename getFileUIDGID to getFileIdentity Aug 18, 2018
testing testing: store containers in map instead of slice for faster lookups Apr 26, 2018
travis-scripts travis: specify full version of deb package Aug 10, 2017
.gitignore Ignore Gopkg.lock and vendor folder Oct 25, 2017
.travis.yml travis: Remove tip as build target Apr 24, 2018
AUTHORS authors: add George MacRorie Aug 13, 2018
DOCKER-LICENSE update docker license url May 10, 2015
Gopkg.toml Back at docker/docker@master Jun 20, 2018
LICENSE license: use standard formatting for text May 2, 2018
Makefile Makefile: simplify targets Feb 27, 2018
README.markdown readme: remove note on supported API version Oct 26, 2017
appveyor.yml appveyor: Go 1.9.7 and 1.10.3 Jun 20, 2018
auth.go Expect auth field to contain colon in all cases Aug 10, 2018
auth_test.go Fix TestAuthConfigIdentityToken configuration Aug 13, 2018
build_test.go Back at docker/docker@master Jun 20, 2018
change.go Update broken short links Oct 22, 2016
change_test.go Run tests in parallel Jul 25, 2017
client.go internal: copy github.com/docker/docker/pkg/jsonmessage Jun 20, 2018
client_stress_test.go Run tests in parallel Jul 25, 2017
client_test.go client: make ContextDeadline test more reliable Mar 3, 2018
client_unix.go Fix code formatting Feb 21, 2018
client_unix_test.go Run tests in parallel Jul 25, 2017
client_windows.go Fix code formatting Feb 21, 2018
client_windows_test.go client_windows_test: add space after buildtag Feb 14, 2017
container.go Move Runtime to HostConfig Jul 2, 2018
container_test.go Add the SHELL command to container Config Mar 6, 2018
container_unix_test.go Removes github.com/hashicorp/go-cleanhttp dependency Aug 9, 2017
distribution.go add support for distribution endpoint Oct 4, 2017
distribution_test.go add support for distribution endpoint Oct 4, 2017
env.go an extra nil check Jul 30, 2018
env_test.go Environment variables may not have a value, currently env.Map blows u… Sep 21, 2017
event.go event: introduce a timeout on monitorEvents Mar 30, 2018
event_test.go event_test: increase timeout Jul 26, 2017
example_test.go Fix example name (reported by vet) Sep 18, 2016
exec.go add WorkingDir option for exec May 1, 2018
exec_test.go add WorkingDir option for exec May 1, 2018
image.go Add missing Target to BuildImageOptions Mar 28, 2018
image_test.go add securityopt arg support Oct 31, 2017
integration_test.go integration_test: use a tagged image Apr 19, 2017
misc.go misc: add VersionWithContext method Apr 24, 2018
misc_test.go Add support for security options in docker system information Oct 9, 2017
network.go Use context from standard library Feb 21, 2018
network_test.go Run tests in parallel Jul 25, 2017
plugin.go Plugin: fix the json tag for enabled Jun 20, 2018
plugins_test.go Plugin: fix the json tag for enabled Jun 20, 2018
signal.go container: provide some constants for signals on KillContainer Apr 27, 2014
swarm.go Use context from standard library Feb 21, 2018
swarm_configs.go Use context from standard library Feb 21, 2018
swarm_configs_test.go Add a swarm_ prefix to all swarm related files Nov 4, 2017
swarm_node.go Use context from standard library Feb 21, 2018
swarm_node_test.go Add a swarm_ prefix to all swarm related files Nov 4, 2017
swarm_secrets.go Use context from standard library Feb 21, 2018
swarm_secrets_test.go Add a swarm_ prefix to all swarm related files Nov 4, 2017
swarm_service.go swarm: support rollback on ServiceUpdate Feb 21, 2018
swarm_service_test.go swarm: support rollback on ServiceUpdate Feb 21, 2018
swarm_task.go Use context from standard library Feb 21, 2018
swarm_task_test.go Add a swarm_ prefix to all swarm related files Nov 4, 2017
swarm_test.go Run tests in parallel Jul 25, 2017
tar.go Copy github.com/docker/docker/pkg/archive to internal/archive Jun 20, 2018
tls.go tls: fix vet failure at tip Apr 23, 2016
volume.go Add CreatedAt to Volume Aug 8, 2018
volume_test.go Add CreatedAt to Volume Aug 8, 2018

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.

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.

Vendoring

go-dockerclient uses dep for vendoring. If you're using dep, you should be able to pick go-dockerclient releases and get the proper dependencies.

With other vendoring tools, users might need to specify go-dockerclient's dependencies manually.

Using with Docker 1.9 and Go 1.4

There's a tag for using go-dockerclient with Docker 1.9 (which requires compiling go-dockerclient with Go 1.4), the tag name is docker-1.9/go-1.4.

The instructions below can be used to get a version of go-dockerclient that compiles with Go 1.4:

% git clone -b docker-1.9/go-1.4 https://github.com/fsouza/go-dockerclient.git $GOPATH/src/github.com/fsouza/go-dockerclient
% git clone -b v1.9.1 https://github.com/docker/docker.git $GOPATH/src/github.com/docker/docker
% go get github.com/fsouza/go-dockerclient