我正在尝试使用go-dockerclient
package main
import (
docker "github.com/fsouza/go-dockerclient"
)
func main () {
h := &docker.HostConfig {
Memory: 4194304,
MemorySwap: -1,
CPUShares: 5,
NetworkMode: "host",
}
client, err := docker.NewClient("unix:///var/run/docker.sock")
config := &docker.Config {
Env: ["FOO=foo"],
Image: "redis",
}
opts := docker.CreateContainerOptions {
Config: config,
HostConfig: hostConfig,
}
container, _ := client.CreateContainer(opts)
err = client.StartContainer(container.ID)
}
这给了我:
:~/gosrc/src/github.com/achanda$ go build
# github.com/achanda
./main.go:16: syntax error: unexpected comma
./main.go:22: non-declaration statement outside function body
./main.go:23: non-declaration statement outside function body
./main.go:24: non-declaration statement outside function body
./main.go:25: syntax error: unexpected }
我似乎没有发现语法有任何问题(不过确实是一个菜鸟)。有什么问题?
答案 0 :(得分:2)
切片文字应如下所示:
[]string{"a", "b", "c"}
不喜欢这样:
["a", "b", "c"]
所以改变这个:
Env: ["FOO=foo"],
对此:
Env: []string{"FOO=foo"},