当我启动docker守护进程时,我正在修改dns服务器,以便容器具有修改后的/etc/resolv.conf。查看我看到的用法消息:
$ docker --help
Usage: docker [OPTIONS] COMMAND [arg...]
A self-sufficient runtime for linux containers.
Options:
--api-enable-cors=false Enable CORS headers in the remote API
-b, --bridge="" Attach containers to a prexisting network bridge
use 'none' to disable container networking
--bip="" Use this CIDR notation address for the network bridge's IP, not compatible with -b
-D, --debug=false Enable debug mode
-d, --daemon=false Enable daemon mode
--dns=[] Force Docker to use specific DNS servers
--dns-search=[] Force Docker to use specific DNS search domains
-e, --exec-driver="native" Force the Docker runtime to use a specific exec driver
... etc ...--dns是我想要传递的,它显示了一个带有[]的'list‘,在经过多次尝试和错误之后,我终于让它起作用了:
--dns 127.0.0.1 --dns 8.8.8.8哪些存款:
nameserver 127.0.0.1
nameserver 8.8.8.8添加到/etc/resolv.conf文件中。
这是向docker (以及任何go)程序提供列表的正确方式吗?
发布于 2015-10-12 06:11:52
这是一种在Go中向程序传递多个参数的方法,但肯定不是唯一的方法。这是通过定义实现Value接口的类型来实现的。flag.Parse()上的flag包遍历参数列表,将名称与已注册的Value匹配,并在Value上调用Set(string)函数。您可以使用它将给定名称的每个值附加到切片。
type numList []int
func (l *numList) String() string {
return "[]"
}
func (l *numList) Set(value string) error {
number, err := strconv.Atoi(value)
if err != nil {
return fmt.Errorf("Unable to parse number from value \"%s\"", value)
}
*l = append(*l, number)
return nil
}这个新类型可以注册为标志变量。在下面的示例中,应用程序接受n个num命令行参数,这些参数被转换为整数并添加到列表中。
var numbers numList
func main() {
flag.Var(&numbers, "num", "A number to add to the summation"
flag.Parse()
sum := 0
for _, num := range numbers {
sum += num
}
fmt.Printf("The sum of your flag arguments is %d.\n", sum)
}这可以通过一个字符串标志轻松地完成,并让用户传递一个分隔列表。在Go语言中没有既定的约定,每个应用程序都可以提供最佳匹配的任何实现。
https://stackoverflow.com/questions/29039031
复制相似问题