2

I have a command that creates a docker container, from a docker container and I want to bind a port to the host

exec(`curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d '{ "Image": "strategy_baseline", "ExposedPorts": { "${PORT}/tcp": {} }, "HostConfig": { "Binds": ["strategies:/usr/src/app/strategies"], "NetworkMode": "titan_backend" }, "PortBindings": { "${PORT}/tcp": [{ "HostPort": "${PORT}" }]}, "Env": ["BOTNAME=${BOT_ID}", "PORT=${PORT}", "ASSETS=${ASSETS}"]}' -X POST http:/v1.4/containers/create?name=${BOT_ID}`,

All variables are properly defined within the file so the error is not there.

As it stands I call this command through an API endpoint, and the container gets created correctly at the correct port running docker ps outputs:

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                          PORTS                                                 NAMES
ab8e28ccd50f        strategy_baseline           "docker-entrypoint.s…"   2 hours ago         Up 2 hours                      3009/tcp                                              defaultKeys

Id expect something that specifies the container port to be 0.0.0.0:3009->3009/tcp. but alas that doesn't work.

I know I can call the container by specifying its name, so from within any other container in the network I can just do http://container_name:3009/endpoint

but ideally I should be able to do: hhtp://vps_ip:3009/endpoint which as of now I cant do.

Any pointer or help is greately appreciated, thanks in advance!!

lucas rodriguez
  • 980
  • 2
  • 8
  • 20

1 Answers1

0

This modification did the trick

exec(`curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" -d '{ "Image": "strategy_baseline", "ExposedPorts": { "${PORT}/tcp": {} }, "HostConfig": { "Binds": ["strategies:/usr/src/app/strategies"], "NetworkMode": "titan_backend", "PortBindings": { "${PORT}/tcp": [{ "HostPort": "${PORT}" }]}}, "Env": ["BOTNAME=${BOT_ID}", "PORT=${PORT}", "ASSETS=${ASSETS}"]}' -X POST http:/v1.4/containers/create?name=${BOT_ID}`,
lucas rodriguez
  • 980
  • 2
  • 8
  • 20