Giter Site home page Giter Site logo

undocker's Introduction

undocker

License: MIT

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

homebrew tap:

$ brew install tokibi/tap/undocker

manually:

Download binany from releases page

go get:

$ go get github.com/tokibi/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)
}

undocker's People

Contributors

ry023 avatar tokibi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

undocker's Issues

Build static binary with alpine environment

Hi,

instead of download the latest (static) release it would be easier to build by go get / go build, but the binary still have dependencies.

Step 10/19 : RUN     ldd $BDIR/undocker
 ---> Running in d5d820f05f47
        /lib/ld-musl-x86_64.so.1 (0x7efdc0b4d000)
        libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7efdc0b4d000)

How to build a static binary with alpine?
Tried with that dockerfile:

ARG     GOBUILD_IMG=golang:alpine

FROM    $GOBUILD_IMG AS gobuild

RUN     apk --update --no-cache add \
        build-base \
        git

ENV     BDIR=/build

WORKDIR $BDIR

RUN     git clone https://github.com/tokibi/undocker.git $BDIR

RUN     go build --ldflags "-s -w -extldflags -static" github.com/tokibi/undocker/cmd/undocker

RUN     ls -lh $BDIR/undocker

RUN     strip $BDIR/undocker

RUN     ldd $BDIR/undocker
RUN     ls -lh $BDIR/undocker

Add symlink absolute to relative conversion

First, thanks for the awesome tool, I originally looked at undocked.py but the Go implementation looks more elaborate and can be installed with a single executable, which is nice.

I have a small feature request that would make a huge difference: I am working on using docker images to produce sysroots meant for cross-compilation outside of a docker container. The main issue I encounter when using the "raw" docker container contents are absolute symlinks that can point to invalid locations on the build host, while they really should be pointing inside the sysroot directory.

One instance of such a problem I encountered is with libgcc_s.so which can often be a symlink to the real .so, unfortunately often set with an absolute path:

$ file ./usr/lib/gcc/i686-linux-gnu/5/libgcc_s.so
./usr/lib/gcc/i686-linux-gnu/5/libgcc_s.so: broken symbolic link to /lib/i386-linux-gnu/libgcc_s.so.1
$ rm ./usr/lib/gcc/i686-linux-gnu/5/libgcc_s.so
$ ln -s ../../../../../lib/i386-linux-gnu/libgcc_s.so.1 ./usr/lib/gcc/i686-linux-gnu/5/libgcc_s.so
$ file ./usr/lib/gcc/i686-linux-gnu/5/libgcc_s.so
./usr/lib/gcc/i686-linux-gnu/5/libgcc_s.so: ELF 32-bit LSB shared object Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=50f0704a5c669c096642b2c5b08b4867bbc9303f, stripped

In the above example, the 32-bit ubuntu sysroot has a libgcc_s.so symlink to '/lib/i386-linux-gnu/libgcc_s.so.1', which obviously makes no sense when outside of the container. Replacing the symlink by '../../../../../lib/i386-linux-gnu/libgcc_s.so.1' (relative) fixes the symlink such that it can point to the right location again.

The Dockerfile I used for this example is simple, it's just an ubuntu environment with a few development packages:

FROM i386/ubuntu:16.04
LABEL maintainer "Devolutions Inc."

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y
RUN apt-get install -y \
    libx11-dev \
    libxtst-dev \
    libxcursor-dev \
    libxrandr-dev \
    libgtk-3-dev \
    libglib2.0-dev \
    libappindicator3-dev \
    libnotify-dev \
    libssl-dev

I then built and extracted its contents this way:

docker build . -t ubuntu-16.04-i386-sysroot
undocker extract ubuntu-16.04-i386-sysroot ./sysroot

Let me know if this could be done, thanks a lot!

Default registry url

Hi @tokibi,

undocker binary is great for some usecases and the smallest binary I found to download and unpack images! Thanks!

You shoult add default registriy url to docker hub and replace if needed with -r?

-r https://registry-1.docker.io/  # should be default

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.