You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Markus Pesch d55209e3f5
fix: update docker API
2 years ago
.drone.yml Intial Commit 2 years ago
.editorconfig Intial Commit 2 years ago
.gitattributes Intial Commit 2 years ago
.gitignore Intial Commit 2 years ago
LICENSE Intial Commit 2 years ago
Makefile Intial Commit 2 years ago
README.md Intial Commit 2 years ago
builder.go fix: update docker API 2 years ago
client.go fix: update docker API 2 years ago
client_test.go fix: update docker API 2 years ago
go.mod fix: update docker API 2 years ago
go.sum fix: update docker API 2 years ago
watcher.go Intial Commit 2 years ago

README.md

dockerutils

Build Status

dockerutils is a small library which extends the official docker library to create and start images over a builder. Additionally the library provide functions for easy removeing resources based on ids, names or labels which the official library does not directly supports.

Installing

Install the library by the following command:

go get git.cryptic.systems/volker.raschek/dockerutils

Usage

Example: Create and remove postgreSQL container

package main

import "git.cryptic.systems/volker.raschek/dockerutils"

func noErr(err){
  if err != nil {
    panic(err)
  }
}

func main(){
  dockerClient, err := dockerutils.New()
  noErr(err)

  postgresContainerID, err := dockerClient.NewBuilder("postgres:13-alpine").
    Port(fmt.Sprintf("5432:5432/tcp", postgresHostPort)).
    Pull().
    AddEnv("PGTZ", "Europe/Berlin").
    AddEnv("POSTGRES_PASSWORD", postgres).
    AddEnv("TZ", "Europe/Berlin").
    Mount("/etc/localtime", "/etc/localtime").
    Start(context.Background())
  noErr(err)
  defer func(){dockerClient.ContainerRemoveByIDs(context.Background(), postgresContainerID)}
}

Example: Create and remove container network

package main

import (
  "git.cryptic.systems/volker.raschek/dockerutils"
  "github.com/docker/docker/api/types"
)

func noErr(err){
  if err != nil {
    panic(err)
  }
}

func main(){
  dockerClient, err := dockerutils.New()
  noErr(err)

  containerNetwork, err := dockerClient.NetworkCreate(ctx, "my-network", tt.NetworkCreate{Labels: map[string]string{"key": "value"}})
  noErr(err)
  defer func(){dockerClient.NetworkRemove(context.Background(), containerNetwork.ID)}
}