我如何使用map struct {}

所以我正忙于使用http://godoc.org/github.com/samalba/dockerclient

使用CreateContainer( http://godoc.org/github.com/samalba/dockerclient#DockerClient.CreateContainer )

设置一个新的容器

containerConfig := &dockerclient.ContainerConfig{ Image: imageName, AttachStdin: true, AttachStdout: true, AttachStderr: true} containerID, err = docker.CreateContainer(containerConfig, containerName) 

工作正常,我得到一个容器,但是,没有暴露的端口。 查看dockerAPI( https://docs.docker.com/reference/api/docker_remote_api_v1.15/ ),我需要设置

“ExposedPorts – 将端口映射到空对象的forms:”ExposedPorts“:{”/:{}“}”

看看我使用的Go dockclient lib的godoc,我看你可以通过它

 ExposedPorts map[string]struct{} 

但我不知道在这里做什么,从docker的例子传递:

  "ExposedPorts":{ "22/tcp": {} } 

是足够的,那么我怎么做我的containerConfig结构位?

把它放在你的containerConfig中

 ExposedPorts: map[string]struct{}{ "22/tcp": {}, } 

例如

 containerConfig := &dockerclient.ContainerConfig{ Image: imageName, AttachStdin: true, AttachStdout: true, AttachStderr: true, ExposedPorts: map[string]struct{}{ "22/tcp": {}, }, } 

操场