Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST API container create and port bindings

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.

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

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

Container was successfully created so as next step I started it with this POST request /containers/$id/start with JSON:

{"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.

Could someone tell me what I am doing wrong? Thanks

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

like image 495
eXPi Avatar asked Nov 10 '22 16:11

eXPi


1 Answers

(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:

   "HostConfig": {
     "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] },
   }
like image 96
BMitch Avatar answered Nov 13 '22 09:11

BMitch