Skip to content

Instantly share code, notes, and snippets.

@brk3
Created April 22, 2015 14:43
Show Gist options
  • Save brk3/185791837fa24e5fcfee to your computer and use it in GitHub Desktop.
Save brk3/185791837fa24e5fcfee to your computer and use it in GitHub Desktop.
package main
import (
"archive/tar"
"bytes"
"github.com/fsouza/go-dockerclient"
"log"
"time"
)
func main() {
client, err := docker.NewClient("unix:///var/run/docker.sock")
if err != nil {
log.Fatal(err)
}
t := time.Now()
inputbuf, outputbuf := bytes.NewBuffer(nil), bytes.NewBuffer(nil)
tr := tar.NewWriter(inputbuf)
tr.WriteHeader(&tar.Header{Name: "Dockerfile", Size: 10, ModTime: t, AccessTime: t, ChangeTime: t})
tr.Write([]byte("FROM fedora:20\n"))
tr.Close()
opts := docker.BuildImageOptions{
Name: "test",
InputStream: inputbuf,
OutputStream: outputbuf,
}
if err := client.BuildImage(opts); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment