Docker Community Forums

Share and learn in the Docker community.

Docker Remote API: Mounting local directory

docker

(Variadico) #1

Hello.

I’m trying to use https://github.com/fsouza/go-dockerclient to reproduce a command I enter in the command line.

Original Command

$ docker run -v "$GOPATH":/go golang:1.5 find /go

Docker Remote API

docker.CreateContainerOptions{
    Name: "my container",
    Config: &docker.Config{
        Mounts: []docker.Mount{
            {Source: os.ExpandEnv("$GOPATH"),
                Destination: "/go",
                RW:          true},
        },
        Image:      "golang:1.5",
        Cmd: []string{"find", "/go"},
    },
}

In the API code, I first create a container. Then, in a separate function call, I start it. The container runs, but find doesn’t find any files. Just an empty skeleton of directories.

Is it possible to do -v /foo:/foo with the Remote API?


(Variadico) #2

The answer is to define both a Mount and Binds.

docker.CreateContainerOptions{
    Name: "my container",
    Config: &docker.Config{
        Mounts: []docker.Mount{
            {Source: os.ExpandEnv("$GOPATH"),
                Destination: "/go",
                RW:          true},
        },
        Image:      "golang:1.5",
        Cmd: []string{"find", "/go"},
    },
    HostConfig: &docker.HostConfig{
        Binds: []string{fmt.Sprintf("%s:%s",os.ExpandEnv("$GOPATH"), "/go")},
    },
}