Skip to content

Go-dexec example #2

@normalfaults

Description

@normalfaults

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions