GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - samalba/dockerclient: Docker client library in Go

This repository was archived by the owner on Mar 18, 2024. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

364 Commits
364 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
mockclient
mockclient
 
 
nopclient
nopclient
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
auth.go
auth.go
 
 
auth_test.go
auth_test.go
 
 
dockerclient.go
dockerclient.go
 
 
dockerclient_test.go
dockerclient_test.go
 
 
engine_mock_test.go
engine_mock_test.go
 
 
example_responses.go
example_responses.go
 
 
interface.go
interface.go
 
 
tls.go
tls.go
 
 
types.go
types.go
 
 
utils.go
utils.go
 
 

Repository files navigation

Docker client library in Go

GoDoc

No longer well-maintained docker client library. Docker's supported engine API client for go is docker/engine-api.

How to use it?

Here is an example showing how to use it:

package main

import (
	"github.com/samalba/dockerclient"
	"log"
	"time"
	"os"
)

// Callback used to listen to Docker's events
func eventCallback(event *dockerclient.Event, ec chan error, 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, 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)
	}

	// Build a docker image
	// some.tar contains the build context (Dockerfile any any files it needs to add/copy)
	dockerBuildContext, err := os.Open("some.tar")
	defer dockerBuildContext.Close()
	buildImageConfig := &dockerclient.BuildImage{
			Context:        dockerBuildContext,
			RepoName:       "your_image_name",
			SuppressOutput: false,
	}
	reader, err := docker.BuildImage(buildImageConfig)
	if err != nil {
		log.Fatal(err)
	}

	// Create a container
	containerConfig := &dockerclient.ContainerConfig{
		Image: "ubuntu:14.04",
		Cmd:   []string{"bash"},
		AttachStdin: true,
		Tty:   true}
	containerId, err := docker.CreateContainer(containerConfig, "foobar", nil)
	if err != nil {
		log.Fatal(err)
	}

	// Start the container
	hostConfig := &dockerclient.HostConfig{}
	err = docker.StartContainer(containerId, hostConfig)
	if err != nil {
		log.Fatal(err)
	}

	// Stop the container (with 5 seconds timeout)
	docker.StopContainer(containerId, 5)

	// 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
  • Michael Crosby
  • Andrea Luzzardi
  • Victor Vieux
  • Evan Hazlett
  • Donald Huang

About

Docker client library in Go

www.docker.com/

Topics

clientdockerengine-apigogolang

Resources

Readme
Apache-2.0 license
Activity

Stars

318 stars

Watchers

2 watching

Forks

138 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.