docker远程api无法将端口绑定到hos

2024-05-19 00:02:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用docker的远程api绑定主机,但总是失败。在

我使用python和urllib2传递这个dict

{
    'Tty':True,
    'Volumes':[],
    'Image':'ubuntu',
    'Cmd':'',
    'WorkingDir':None,
    'Entrypoint':None,
    'Env':None,
    'AttachStdin':False,
    'AttachStdout':True,
    'AttachStderr':True,
    'OpenStdin':True,
    'ExposedPorts':{'80/tcp':{}},
    'HostConfig':{'PortBindings':{'80/tcp':['15080']}}
}

然后我使用远程api来检查容器,它给出了以下信息:

^{pr2}$

我还尝试使用这个链接Binding a port to a host interface using the REST API中的方法, 但是当我发布数据来启动容器时,它将引发HTTP错误500。所以我猜docker远程api是否被更改了。在


Tags: dockerimagecmdnoneapitrue远程ubuntu
1条回答
网友
1楼 · 发布于 2024-05-19 00:02:07

您的PortBindings参数似乎有点不正常。您缺少"HostPort":

更改为:

'HostConfig':{'PortBindings':{'80/tcp':[{ "HostPort": '15080' }] }}

docs

  • PortBindings - A map of exposed container ports and the host port they should map to. It should be specified in the form { <port>/<protocol>: [{ "HostPort": "<port>" }] } Take note that port is specified as a string and not an integer value.

相关问题 更多 >

    热门问题