4

I'm trying to start docker container with docker's Remote API. I could able to start the container but unable to expose and map the container's port to host port.

I need Remote API JSON for following ssh command

docker run -i -t --expose 80 -p 80:80 my_image_nodejs nodejs /var/www/server.js

Right now i'm using below JSON.

{
    "Image": "f96f6e304cfcd630ee51af87baf30dfd42cf1f361da873a2f62ce6654d7a4c6b",
    "Memory": 0,
    "MemorySwap": 0,
    "VolumesFrom": "",
    "Cmd": [
        "nodejs",
        "/var/www/server.js",
        "-D"
    ],
    "PortBindings": {
        "80/tcp": [
            {
                "HostIp": "0.0.0.0",
                "HostPort": "80"
            }
        ]
    },
    "ExposedPorts": {
        "80/tcp": {}
    }
}

Thanks in advance

0

2 Answers 2

5

This works for me :

Container create :

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

Container start :

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

If you know how to set up Env, I've just sent my question :-)

0
1

I believe your request should be below:

curl -X POST -H "Content-Type: application/json" -d '{
    "AttachStdin":false,"AttachStdout":true,"AttachStderr":true,
    "ExposedPorts": { "80/tcp": {}},
    "Cmd": [
        "nodejs","/var/www/server.js","-D"
    ],
    "HostConfig":{
        "PortBindings": { "80/tcp": [{ "HostPort": "80" }] }
    },
    "Image":"my_image_nodejs",
    "Tag":"latest"
}' $DOCKER_DAEMON/containers/create

where $DOCKER_DAEMON is the host listening remote requests. The PortBindings and ExposedPorts are in different sections. You may want to refer more detail on Docker remote API v1.22.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.