Docker Community Forums

Share and learn in the Docker community.

How to point different scripts to different containers


(Willie108) #1

I ran
docker run -d -p 9200:9200 -p 5601:5601 nshou/elasticsearch-kibana

docker run -d -p 9204:9200 -p 5604:5601 nshou/elasticsearch-kibana

after running these I can access at ports 9200 and 9204 (and 5601 and 5604).

and have
root@dgone:~# docker run -d -p 9204:9200 -p 5604:5601 nshou/elasticsearch-kibana
4c3cc4cdba39c53a96aa7dbfd1ed033a5ea76aa1d0f90c326cead5a606bff074
root@dgone:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c3cc4cdba39 nshou/elasticsearch-kibana “/bin/sh -c 'elastics” 16 seconds ago Up 15 seconds 0.0.0.0:5604->5601/tcp, 0.0.0.0:9204->9200/tcp trustinggolick
6b510d76d8a8 nshou/elasticsearch-kibana “/bin/sh -c 'elastics” 9 hours ago Up 4 minutes 0.0.0.0:5601->5601/tcp, 0.0.0.0:9200->9200/tcp kickassvolhard

I have two python scripts in usr/bin
called t1.py and t2.py each of which use code like

from elasticsearch import Elasticsearch
es = Elasticsearch()
es.index(index=“sentiment”,
doc_type=“test-type”,
body={“author”: dict_data[“user”][“screen_name”],
“favoriteCount”: dict_data[“favorite_count”],
“subjectivity”: tweet.sentiment.subjectivity,
“sentiment”: sentiment})

I don’t understand how to have t1.py send data to trustinggolick and have t2.py send data to kickassvolhard


(Richardpayne) #2

Firstly, if you’re referencing containers in scripts then you should probably use the --name option on the run commands to give your containers fixed names. trustinggolick and kickassvolhard will not be the container names next time you run them.

As for your script, you don’t appear to be referencing a server anywhere. How does your elasticsearch code know which server address and port to use?


(Richardpayne) #3

I’ve just seen your other post:
https://forums.docker.com/t/multiple-instances-containers-of-elasticsearch-on-docker/13264?source_topic_id=13408

It’s generally a good idea, on all forums, to only post one thread for each issue. Posting multiples like that splits the responses you get and makes it harder for people to get useful information on your problem.
Unfortunately, I don’t seem to have the “flag” option to bring it to mods attention. Hopefully they’ll see this and merge the two threads.

Equally unfortunately, the code in the other thread doesn’t really shed any light on the problem. I still don’t see anywhere in the code that references the server. Is it specified in a configuration file somewhere?


(Willie108) #4

Hi, thanks very much for the suggestion about the --name option. I apologize for the duplicate post. I tried looking for my post and could not find it and so I repeated it.
Can you suggest how I can reference the server in the script? That is I think what I wanted to figure out. Also, by referencing the server, does that mean the container. I think what I want to do is reference the container (and port) right?


(Richardpayne) #5

No, you need to use the docker host and port.
If the host machine is called “dockerhost” then:

The first container is accessible on dockerhost:9200
The second container is accessible on dockerhost:9204

If you’re looking for help on how to write your Python code then this is probably the wrong place to ask. Stack Overflow or the ElasticSearch library author’s page would be the best place to ask.