bfirsh / bfirsh/serverless-docker

Go-dexec example

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
307
Forks
20
PR merge metrics
No merged PRs in 30d

Description

Example using go-dexec i'll probably demo...

```
package main

import (

"net/http"
"github.com/fsouza/go-dockerclient"
"log"

"github.com/ahmetalpbalkan/dexec"

"io"
"fmt"
)

func hello(w http.ResponseWriter, r *http.Request) {
cl, _ := docker.NewClient("unix:///var/run/docker.sock")
d := dexec.Docker{cl}

m, _ := dexec.ByCreatingContainer(docker.CreateContainerOptions{
Config: &docker.Config{Image: "busybox"}})

cmd := d.Command(m, "echo", `I am running inside a container!`)
b, err := cmd.Output()
if err != nil { log.Fatal(err) }
log.Printf("%s", b)
io.WriteString(w, fmt.Sprintf("%s", b))

}

func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8000", nil)
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.