json REST API 容器创建和端口绑定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20630919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 20:07:25  来源:igfitidea点击:

REST API container create and port bindings

jsonrestdockerlxc

提问by eXPi

I have image from dockerfile, which setup container, but I need to create and start containers with docker REST API. Problem is that I have issue with exposing ssh port. I have removed EXPOSE from dockerfile, and build image.

我有来自 dockerfile 的图像,它设置容器,但我需要使用 docker REST API 创建和启动容器。问题是我在暴露 ssh 端口时遇到了问题。我已经从 dockerfile 中删除了 EXPOSE,并构建了镜像。

After that I made POST request on /containers/create with this json:

之后,我使用此 json 在 /containers/create 上发出 POST 请求:

{"Image":"frantiseks/apac","ExposedPorts":{"22/tcp":{}},"Memory":600000,"CpuShares":50}

Container was successfully created so as next step I started it with this POSTrequest /containers/$id/startwith JSON:

容器已成功创建,因此下一步我使用 JSONPOST请求 启动它/containers/$id/start

{"PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }}

But after inspect container I do not see mapped ports, so container does not exposed 22 to host 11022 port. I am using version 0.7.1.

但是在检查容器之后我没有看到映射的端口,所以容器没有将 22 暴露给主机 11022 端口。我使用的是 0.7.1 版。

Could someone tell me what I am doing wrong? Thanks

有人能告诉我我做错了什么吗?谢谢

PS: Inspected container: http://jsonblob.com/52b01e45e4b0439bc58ec8d4

PS:检查容器:http: //jsonblob.com/52b01e45e4b0439bc58ec8d4

回答by BMitch

(Apologies for the late answer, "community" decided to bump your question)

(抱歉回答晚了,“社区”决定撞你的问题)

With the current 1.24 api, this is all done in the container create. You need to include the following there:

使用当前的 1.24 api,这一切都在容器创建中完成。您需要在那里包含以下内容:

   "HostConfig": {
     "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] },
   }

回答by Alex Shuraits

Did you try: {HostIp:"", HostPort:"11022"}?

你有没有试过: {HostIp:"", HostPort:"11022"}