0

I have an app in Python that I want to run in a Docker container and it has a line:

h2o.connect(ip='127.0.0.1', port='54321')

The h2o server is running in a Docker container and it always has a different IP. One time it was started on 172.19.0.5, the other time 172.19.0.3, sometimes 172.17.0.3. So it is always random, and I can't connect the Python app. I tried to expose the port of h2o server to localhost and then connect the Python (the code above), but it is not working.

1

1 Answer 1

0

You dont connect two docker containers though ip addresses. Instead, you want to use docker internal network aliases:

version: '3'
services:
  server:
    ...
    depends_on:
      - database
  database:
    ...
    expose:
      - 54321:54321

then you can define your connectio in server as: h2o.connect(ip='127.0.0.1', port='54321')

7
  • 1
    correction: version: '3' services: server: ... depends_on: - database database: ... expose: - 54321 and h2o.connect(ip='database', port='54321') Jul 4, 2018 at 9:02
  • correct me if i am wrong, but i think that ports: declaration is sufficient when communicating between two linked docker images. You would want to expose: the port only when you want to open the container to external connections? Jul 4, 2018 at 9:09
  • Thank you very much, it worked, I used depends_on: theThingItDependsOn and then in my python code I wrote ip=*theThingItDependsOn* Jul 4, 2018 at 10:30
  • But it is programming and now I have a different problem. Now because the h2o server and python are running in the docker, the windows path C:/Desktop/Data/data.csv is not visible, because is somewhere in a container. How do I insert the csv file in the container and specify the path? Do I use volume or is there an easiear solution? Jul 4, 2018 at 10:36
  • 1
    Simas, it's the opposite. "ports" will publish the port to the host - that's why the format is "dest:source" Jul 5, 2018 at 8:40

Your Answer

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

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