【发布时间】:2014-12-02 20:22:27
【问题描述】:
所以我忙着用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)
工作正常,我得到了一个容器,但是,没有暴露的端口。查看docker API(https://docs.docker.com/reference/api/docker_remote_api_v1.15/),需要设置
"ExposedPorts - 将端口映射到空对象的对象,格式为:"ExposedPorts": { "/: {}" }"
查看我正在使用的 Go dockclient 库的 godoc,我看到您可以将其传递为
ExposedPorts map[string]struct{}
但我不知道在这里做什么,来自 docker api 示例传递:
"ExposedPorts":{
"22/tcp": {}
}
足够了,那么我的containerConfig中的struct位怎么做呢?
【问题讨论】: