forked from cassiobotaro/60-days-of-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
36 lines (33 loc) · 877 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"log"
docker "github.com/fsouza/go-dockerclient"
uuid "github.com/satori/go.uuid"
)
// code extracted from https://github.com/gofn/docker-in-docker
func main() {
// connect to docker client
// this code will run inside the container, but uses host socket to
// create new containers
endpoint := "unix:///var/run/docker.sock"
client, err := docker.NewClient(endpoint)
if err != nil {
log.Fatal(err)
}
// create containers with random names
container, err := client.CreateContainer(docker.CreateContainerOptions{
Name: fmt.Sprintf("gofn-%s", uuid.NewV4().String()),
Config: &docker.Config{
Image: "debian:8",
StdinOnce: true,
OpenStdin: true,
},
})
if err != nil {
log.Fatal(err)
}
// if nothing wrong happens, print created container inside host
fmt.Println(container)
fmt.Println("Container created!")
}