Docker equivalent remote API command for -p 80:80?

I am trying to run a docker container with the docker remote API. I was able to start the container, but could not open and map the container port to the host port.

I need a remote JSON API for the next ssh command

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

I am using below JSON now.

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

+4
source share
2 answers

This works for me:

The container creates :

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

Beginning of the container :

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

If you know how to configure Env, I just posted my question :-)

+4

, :

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

$DOCKER_DAEMON - , . PortBindings ExposedPorts . API Docker v1.22.

, .

+1

Source: https://habr.com/ru/post/1543724/


All Articles