undocker

package module
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2020 License: MIT Imports: 24 Imported by: 0

README

undocker

Go library and command line tool for decomposing docker images.

Command Use

Usage
NAME:
   undocker - Decompose docker images.

USAGE:
   undocker [global options] command [command options] [arguments...]

VERSION:
   0.1.3

COMMANDS:
     extract, e  Extract to rootfs.
     show, s     Show image informations
     help, h     Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --registry-url value, -r value   docker registry url [$REGISTRY_URL]
   --registry-user value, -u value  docker registry login username [$REGISTRY_USER]
   --registry-pass value, -p value  docker registry login password [$REGISTRY_PASS]
   --help, -h                       show help
   --version, -v                    print the version
Installation

manually:

Download binany from releases page

go get:

$ go get github.com/pepabo/undocker/cmd/undocker
Extract

Extract from local images.

$ undocker extract busybox:latest ./image
$ ls ./image
bin/  dev/  etc/  home/  root/	tmp/  usr/  var/

Extract directly from docker registry.

$ export REGISTRY_USER=xxx # optional
$ export REGISTRY_PASS=xxx # optional
$ undocker -r "https://registry-1.docker.io/" extract busybox:latest ./image
Config

Show image config.

$ undocker show config busybox:latest | jq
{
  "architecture": "amd64",
  "config": {
    "Hostname": "",
    "Domainname": "",
    "User": "",
    "AttachStdin": false,
    "AttachStdout": false,
    "AttachStderr": false,
    "Tty": false,
    "OpenStdin": false,
    "StdinOnce": false,
    "Env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    ],
    "Cmd": [
      "sh"
    ],
...

Library Use

Extract

Extract from local images.

func main() {
    dst := "./image"

    api, err := undocker.NewDockerAPI()
    if err != nil {
        log.Fatal(err)
    }
    api.Image("busybox", "latest").Extract(dst, false)
}

Extract directly from docker registry.

func main() {
    url := "https://registry-1.docker.io/"
    username := ""
    password := ""
    dst := "./image"

    registry, err := undocker.NewRegistry(url, username, password)
    if err != nil {
        log.Fatal(err)
    }
    registry.Image("busybox", "latest").Extract(dst, false)
}
Config
func main() {
    api, _ := undocker.NewDockerAPI()
    config, err := api.Image("busybox", "latest").Config()
    if err != nil {
        return err
    }
    fmt.Println(config.architecture)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Hostname     string            `json:"Hostname"`
	Domainname   string            `json:"Domainname"`
	User         string            `json:"User"`
	AttachStdin  bool              `json:"AttachStdin"`
	AttachStdout bool              `json:"AttachStdout"`
	AttachStderr bool              `json:"AttachStderr"`
	Tty          bool              `json:"Tty"`
	OpenStdin    bool              `json:"OpenStdin"`
	StdinOnce    bool              `json:"StdinOnce"`
	Env          []string          `json:"Env"`
	Cmd          []string          `json:"Cmd"`
	ArgsEscaped  bool              `json:"ArgsEscaped"`
	Image        string            `json:"Image"`
	Volumes      []string          `json:"Volumes"`
	WorkingDir   string            `json:"WorkingDir"`
	Entrypoint   []string          `json:"Entrypoint"`
	OnBuild      []string          `json:"OnBuild"`
	Labels       map[string]string `json:"Labels"`
}

type ContainerConfig

type ContainerConfig struct {
	Hostname     string            `json:"Hostname"`
	Domainname   string            `json:"Domainname"`
	User         string            `json:"User"`
	AttachStdin  bool              `json:"AttachStdin"`
	AttachStdout bool              `json:"AttachStdout"`
	AttachStderr bool              `json:"AttachStderr"`
	Tty          bool              `json:"Tty"`
	OpenStdin    bool              `json:"OpenStdin"`
	StdinOnce    bool              `json:"StdinOnce"`
	Env          []string          `json:"Env"`
	Cmd          []string          `json:"Cmd"`
	ArgsEscaped  bool              `json:"ArgsEscaped"`
	Image        string            `json:"Image"`
	Volumes      []string          `json:"Volumes"`
	WorkingDir   string            `json:"WorkingDir"`
	Entrypoint   []string          `json:"Entrypoint"`
	OnBuild      []string          `json:"OnBuild"`
	Labels       map[string]string `json:"Labels"`
}

type DockerAPI

type DockerAPI struct {
	// contains filtered or unexported fields
}

func NewDockerAPI

func NewDockerAPI() (*DockerAPI, error)

func (DockerAPI) CleanUp

func (api DockerAPI) CleanUp() error

func (DockerAPI) Config

func (api DockerAPI) Config(repository, tag string) ([]byte, error)

func (DockerAPI) Exists

func (api DockerAPI) Exists(repository, tag string) bool

func (DockerAPI) Find

func (api DockerAPI) Find(repository, tag string) (string, error)

func (DockerAPI) Image

func (api DockerAPI) Image(repository, tag string) Image

func (DockerAPI) ImageBlob

func (api DockerAPI) ImageBlob(repository, tag string) (*ImageBlob, error)

func (DockerAPI) LayerBlobs

func (api DockerAPI) LayerBlobs(repository, tag string) ([]io.Reader, error)

type History

type History []struct {
	Created    time.Time `json:"created"`
	CreatedBy  string    `json:"created_by"`
	EmptyLayer bool      `json:"empty_layer,omitempty"`
}

type Image

type Image struct {
	Source     Source
	Repository string
	Tag        string
}

func (Image) Config

func (i Image) Config() (*ImageConfig, error)

func (Image) Exists

func (i Image) Exists() bool

Exists check the images

func (Image) Extract

func (i Image) Extract(dir string, overwriteSymlink bool) error

Extract extracts docker image as rootfs to the specified directory

func (Image) LayerBlobs

func (i Image) LayerBlobs() ([]io.Reader, error)

LayerBlobs return the layers of the image in order from the lower

func (Image) Unpack

func (i Image) Unpack(dir string, overwriteSymlink bool) error

Unpack is an alias for Extract()

type ImageBlob

type ImageBlob struct {
	Blob io.ReadCloser
}

func (*ImageBlob) Config

func (i *ImageBlob) Config() ([]byte, error)

func (*ImageBlob) LayerBlobs

func (i *ImageBlob) LayerBlobs() ([]io.Reader, error)

func (*ImageBlob) Manifest

func (i *ImageBlob) Manifest() (Manifest, error)

type ImageConfig

type ImageConfig struct {
	Architecture    string          `json:"architecture"`
	Config          Config          `json:"config"`
	Container       string          `json:"container"`
	ContainerConfig ContainerConfig `json:"container_config"`
	Created         time.Time       `json:"created"`
	DockerVersion   string          `json:"docker_version"`
	History         History         `json:"history"`
	OS              string          `json:"os"`
	Rootfs          Rootfs          `json:"rootfs"`
}

type Manifest

type Manifest struct {
	Config   string   `json:"Config"`
	RepoTags []string `json:"RepoTags"`
	Layers   []string `json:"Layers"`
}

type Options

type Options struct {
	RegistryURL  string
	RegistryUser string
	RegistryPass string
	TmpPath      string
	Extract      untar.Options
}

type Registry

type Registry struct {
	URL      *url.URL
	Username string
	Password string
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry(baseURL, username, password, tmpRoot string) (*Registry, error)

func (Registry) CleanUp

func (r Registry) CleanUp() error

func (Registry) Config

func (r Registry) Config(repository, tag string) ([]byte, error)

func (Registry) Exists

func (r Registry) Exists(repository, tag string) bool

func (Registry) ExtractedBlob

func (r Registry) ExtractedBlob(repository string, digest digest.Digest) (io.Reader, error)

func (Registry) Find

func (r Registry) Find(repository, tag string) error

func (Registry) Image

func (r Registry) Image(repository, tag string) Image

func (Registry) LayerBlobs

func (r Registry) LayerBlobs(repository, tag string) ([]io.Reader, error)

func (Registry) Layers

func (r Registry) Layers(repository, tag string) ([]distribution.Descriptor, error)

func (Registry) Manifest

func (r Registry) Manifest(repository, tag string) (*schema2.DeserializedManifest, error)

type Rootfs

type Rootfs struct {
	Type    string   `json:"type"`
	DiffIds []string `json:"diff_ids"`
}

type Source

type Source interface {
	Config(repository, tag string) ([]byte, error)
	Exists(repository, tag string) bool
	LayerBlobs(repository, tag string) ([]io.Reader, error)
	Image(repository, tag string) Image
	CleanUp() error
}

type Undocker

type Undocker struct {
	Out, Err io.Writer
}

func (Undocker) Config

func (u Undocker) Config(repo, tag string, opts Options) error

func (Undocker) Extract

func (u Undocker) Extract(repo, tag, dest string, opts Options) error

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL