0
docker run -d --link selenium-hub:hub --expose 7092 selenium/node-chrome

Here's docker link

I want to code above expose option using python docker api.

As a result i want 7092 port should be exposed to selenium/node-chrome docker.

Result:

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                    NAMES

1fcb8c15a059        selenium/node-chrome   "/opt/bin/entry_point"   7 seconds ago       Up 6 seconds        7092/tcp                 selenium-node-chrome

Please help me in this, thanks in advance.

DanteTheSmith
  • 2,937
  • 1
  • 16
  • 31
kanishk
  • 91
  • 9

2 Answers2

0

You need to specify a port mapping like docker run -d --link selenium-hub:hub --expose 7092 selenium/node-chrome -p 7092:7092. First number is the port that will be exposed, the second one is the port it gets mapped to in the container.

See here to get the official docker run reference.

There is another SO thread explaining the difference between exposing a port and publishing it.

hecko84
  • 1,224
  • 1
  • 16
  • 29
  • Expose option is working for me, thats not the issue. i want to automate it using python [Library](https://docker-py.readthedocs.io/en/stable/client.html) – kanishk Dec 11 '17 at 17:40
0

To only expose a port to other docker containers but not the host, this worked for me:

import docker
from docker.models.containers import Container
client = docker.from_env()
container: Container = client.containers.run(
    ...
    ports={5432: []},
    ...
)
Tobias Ernst
  • 4,214
  • 1
  • 32
  • 30