Skip to content
Go client for the Docker Engine API.
Go Other
  1. Go 99.8%
  2. Other 0.2%
Branch: master
Clone or download

Latest commit

Latest commit 6aaf6c2 Jun 12, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Revert "github/workflows: add go 1.15beta1" Jun 11, 2020
testing Fix/disable lint violations May 5, 2020
.gitattributes Try to fix travis on Windows with .gitattributes Sep 18, 2019
.gitignore gitignore: remove dep stuff Sep 17, 2019
.golangci.yaml Fix/disable lint violations May 5, 2020
AUTHORS authors: add Umut Çömlekçioğlu Jun 2, 2020
DOCKER-LICENSE update docker license url May 10, 2015
LICENSE Happy New Year Jan 24, 2020
Makefile Migrate from Travis & AppVeyor to GH Actions (#824) Mar 9, 2020
README.md Update docs readme link (#825) Mar 13, 2020
auth.go golangci: disable godot, nestif and testpackage Apr 23, 2020
auth_test.go Fix/disable lint violations May 5, 2020
build_test.go Fix/disable lint violations May 5, 2020
change.go Update broken short links Oct 22, 2016
change_test.go Reformat code Jun 14, 2019
client.go golangci: disable godot, nestif and testpackage Apr 23, 2020
client_stress_test.go Address some violations reported by gopls Apr 1, 2020
client_test.go Fix/disable lint violations May 5, 2020
client_unix.go Address some violations reported by golangci-lint Feb 13, 2019
client_unix_test.go Address some violations reported by gopls Apr 1, 2020
client_windows.go client_windows: disable unparam for a specific check Sep 16, 2019
client_windows_test.go client: remove redundant build tags Apr 10, 2019
container.go Container operations divided separate files (#832) Jun 2, 2020
container_archive.go Container operations divided separate files (#832) Jun 2, 2020
container_archive_test.go
container_attach.go Container operations divided separate files (#832) Jun 2, 2020
container_attach_test.go Container operations divided separate files (#832) Jun 2, 2020
container_changes.go Container operations divided separate files (#832) Jun 2, 2020
container_changes_test.go Container operations divided separate files (#832) Jun 2, 2020
container_commit.go Container operations divided separate files (#832) Jun 2, 2020
container_commit_test.go Container operations divided separate files (#832) Jun 2, 2020
container_copy.go Container operations divided separate files (#832) Jun 2, 2020
container_copy_test.go Container operations divided separate files (#832) Jun 2, 2020
container_create.go Container operations divided separate files (#832) Jun 2, 2020
container_create_test.go Container operations divided separate files (#832) Jun 2, 2020
container_export.go Container operations divided separate files (#832) Jun 2, 2020
container_export_test.go Container operations divided separate files (#832) Jun 2, 2020
container_inspect.go Container operations divided separate files (#832) Jun 2, 2020
container_inspect_test.go Container operations divided separate files (#832) Jun 2, 2020
container_kill.go Container operations divided separate files (#832) Jun 2, 2020
container_kill_test.go Container operations divided separate files (#832) Jun 2, 2020
container_list.go Container operations divided separate files (#832) Jun 2, 2020
container_list_test.go Container operations divided separate files (#832) Jun 2, 2020
container_logs.go Container operations divided separate files (#832) Jun 2, 2020
container_logs_test.go Move tests for NoSuchContainer to container_test.go Jun 2, 2020
container_pause.go Container operations divided separate files (#832) Jun 2, 2020
container_pause_test.go Container operations divided separate files (#832) Jun 2, 2020
container_prune.go Container operations divided separate files (#832) Jun 2, 2020
container_prune_test.go Container operations divided separate files (#832) Jun 2, 2020
container_remove.go Container operations divided separate files (#832) Jun 2, 2020
container_remove_test.go Container operations divided separate files (#832) Jun 2, 2020
container_rename.go Container operations divided separate files (#832) Jun 2, 2020
container_rename_test.go Container operations divided separate files (#832) Jun 2, 2020
container_resize.go Container operations divided separate files (#832) Jun 2, 2020
container_resize_test.go Container operations divided separate files (#832) Jun 2, 2020
container_restart.go Container operations divided separate files (#832) Jun 2, 2020
container_restart_test.go Container operations divided separate files (#832) Jun 2, 2020
container_start.go Container operations divided separate files (#832) Jun 2, 2020
container_start_test.go Container operations divided separate files (#832) Jun 2, 2020
container_stats.go Container operations divided separate files (#832) Jun 2, 2020
container_stats_test.go Container operations divided separate files (#832) Jun 2, 2020
container_stop.go Container operations divided separate files (#832) Jun 2, 2020
container_stop_test.go Container operations divided separate files (#832) Jun 2, 2020
container_test.go Move tests for NoSuchContainer to container_test.go Jun 2, 2020
container_top.go Container operations divided separate files (#832) Jun 2, 2020
container_top_test.go Container operations divided separate files (#832) Jun 2, 2020
container_unix_test.go Fix staticcheck violations on Windows Feb 10, 2019
container_unpause.go Container operations divided separate files (#832) Jun 2, 2020
container_unpause_test.go Container operations divided separate files (#832) Jun 2, 2020
container_update.go Container operations divided separate files (#832) Jun 2, 2020
container_update_test.go Container operations divided separate files (#832) Jun 2, 2020
container_wait.go Container operations divided separate files (#832) Jun 2, 2020
container_wait_test.go Container operations divided separate files (#832) Jun 2, 2020
distribution.go Migrate from staticcheck to golangci-lint Sep 16, 2019
distribution_test.go Add missing copyright banner Jan 10, 2019
env.go an extra nil check Jul 30, 2018
env_test.go Reformat code Jun 14, 2019
event.go client, event: "address" some staticcheck violations Sep 23, 2019
event_test.go Address some violations reported by gopls Apr 1, 2020
example_test.go Run gofumpt Apr 10, 2019
exec.go container, exec: add DetachKeys to attach and exec Sep 23, 2019
exec_test.go Address some violations reported by gopls Apr 1, 2020
go.mod build(deps): bump github.com/google/go-cmp from 0.4.0 to 0.4.1 May 15, 2020
go.sum build(deps): bump github.com/google/go-cmp from 0.4.0 to 0.4.1 May 15, 2020
helpers_test.go Fix more gopls violations Apr 1, 2020
image.go Add missing Comment field to ImageHistory Sep 27, 2019
image_test.go Fix/disable lint violations May 5, 2020
integration_test.go integration_test: no arch for PullImage Platform Aug 27, 2019
integration_unix_test.go Migrate from staticcheck to golangci-lint Sep 16, 2019
integration_windows_test.go Migrate from staticcheck to golangci-lint Sep 16, 2019
misc.go Migrate from staticcheck to golangci-lint Sep 16, 2019
misc_test.go Migrate from staticcheck to golangci-lint Sep 16, 2019
network.go Migrate from staticcheck to golangci-lint Sep 16, 2019
network_test.go Migrate from staticcheck to golangci-lint Sep 16, 2019
plugin.go Add GetPluginPrivilegesWithOptions to support registry authentication Oct 8, 2019
plugin_test.go Add GetPluginPrivilegesWithOptions to support registry authentication Oct 8, 2019
registry_auth.go image, swarm: don't send empty auth headers to the remote daemon Oct 2, 2018
signal.go container: provide some constants for signals on KillContainer Apr 27, 2014
swarm.go Migrate from staticcheck to golangci-lint Sep 16, 2019
swarm_configs.go Migrate from staticcheck to golangci-lint Sep 16, 2019
swarm_configs_test.go Fix more gopls violations Apr 1, 2020
swarm_node.go Migrate from staticcheck to golangci-lint Sep 16, 2019
swarm_node_test.go Fix more gopls violations Apr 1, 2020
swarm_secrets.go Migrate from staticcheck to golangci-lint Sep 16, 2019
swarm_secrets_test.go Fix more gopls violations Apr 1, 2020
swarm_service.go
swarm_service_test.go Address some violations reported by gopls Apr 1, 2020
swarm_task.go Migrate from staticcheck to golangci-lint Sep 16, 2019
swarm_task_test.go Fix more gopls violations Apr 1, 2020
swarm_test.go Fix/disable lint violations May 5, 2020
system.go Migrate from staticcheck to golangci-lint Sep 16, 2019
system_test.go added diskUsage Sep 18, 2018
tar.go tar: changes in error handling Mar 1, 2020
tls.go tls: drop NameToCertificate Dec 19, 2019
volume.go Migrate from staticcheck to golangci-lint Sep 16, 2019
volume_test.go Migrate from staticcheck to golangci-lint Sep 16, 2019

README.md

go-dockerclient

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.

For more details, check the remote API documentation.

Difference between go-dockerclient and the official SDK

Link for the official SDK: https://docs.docker.com/develop/sdk/

go-dockerclient was created before Docker had an official Go SDK and is still maintained and active because it's still used out there. New features in the Docker API do not get automatically implemented here: it's based on demand, if someone wants it, they can file an issue or a PR and the feature may get implemented/merged.

For new projects, using the official SDK is probably more appropriate as go-dockerclient lags behind the official SDK.

When using the official SDK, keep in mind that because of how the its dependencies are organized, you may need some extra steps in order to be able to import it in your projects (see #784 and moby/moby#28269).

Example

package main

import (
	"fmt"

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

func main() {
	client, err := docker.NewClientFromEnv()
	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"

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

func main() {
	const 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, DOCKER_API_VERSION, you can use NewClientFromEnv.

package main

import (
	"fmt"

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

func main() {
	client, err := docker.NewClientFromEnv()
	if err != nil {
		// handle err
	}
	// 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 run all checks, as well as install any required dependencies.

Modules

go-dockerclient supports Go modules.

If you're using dep, you can check the releases page for the latest release fully compatible with dep.

With other vendoring tools, users 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
You can’t perform that action at this time.