douwo8140 2014-12-02 12:00
浏览 106
已采纳

如何使用map [string] struct {}

So I am busy using http://godoc.org/github.com/samalba/dockerclient

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

To setup a new container

containerConfig := &dockerclient.ContainerConfig{
    Image:        imageName,
    AttachStdin:  true,
    AttachStdout: true,
    AttachStderr: true}

containerID, err = docker.CreateContainer(containerConfig, containerName)

works correctly and I get a container, however, there is no exposed ports. Looking at the docker API(https://docs.docker.com/reference/api/docker_remote_api_v1.15/), I need to set

"ExposedPorts - An object mapping ports to an empty object in the form of: "ExposedPorts": { "/: {}" }"

Looking at the godoc for the Go dockclient lib I am using, I see you can pass it as

ExposedPorts    map[string]struct{}

But I have no idea on what to do here, from the docker api example passing :

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

is enough, so how do I do the struct bit in the my containerConfig?

  • 写回答

1条回答 默认 最新

  • dongzha3058 2014-12-02 12:22
    关注

    Put this in your containerConfig

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

    Eg

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

    Playground

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料