I have a docker-compose.yml file:
zookeeper:
image: zookeeper:3.4
ports:
- 2181:2181
kafka:
image: ches/kafka:latest
ports:
- 9092:9092
links:
- zookeeper:3.4
myDpm:
image: dpm-image:latest
ports:
- 9000:9000
links:
- kafka:latest
mySql:
image: mysql:latest
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
myMc3:
image: mc3-v3:3.0
ports:
- 9001:9000
links:
- mySql:latest
environment:
runMode: dev
myElastic:
image: elasticsearch:2.4.0
ports:
- 9200:9200
Running docker-compose up -d creates the container for all the image files.
Please note that i have created images for all already so these images will not be pulled from server when i run the docker-compose.yml file.
All the containers are running successfully but the problem turns out to be that containers cannot interact with each other like i have used links in my docker-compose.yml file to provide communicate between containers. But i think links option is not working for me. Kakfa is not able to communication with zookeeper(I used links to link zookeeper and kafka).
In short, Why link option is not working?
Or i am going wrong somewhere? Anyone please provide me the right direction.
Note: All the containers are working separately but not able to communicate with each other
Links are to the service name, not to the image name:
zookeeper:
image: zookeeper:3.4
ports:
- 2181:2181
kafka:
image: ches/kafka:latest
ports:
- 9092:9092
links:
- zookeeper
myDpm:
image: dpm-image:latest
ports:
- 9000:9000
links:
- kafka
mySql:
image: mysql:latest
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
myMc3:
image: mc3-v3:3.0
ports:
- 9001:9000
links:
- mySql
environment:
runMode: dev
myElastic:
image: elasticsearch:2.4.0
ports:
- 9200:9200
So, ie, you can point to zookeeper
from kafka
as this:
zookeeper:2181
PS: You don't need to expose ports if you only use containers inter connections (as example before). You expose ports when you need to access, ie to some service port through your localhost.
The issue is you are linking your containers improperly. To link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name. See the docker compose documentation for further information. Corrected compose file.
zookeeper:
image: zookeeper:3.4
ports:
- 2181:2181
kafka:
image: ches/kafka:latest
ports:
- 9092:9092
links:
- zookeeper
myDpm:
image: dpm-image:latest
ports:
- 9000:9000
links:
- kafka
mySql:
image: mysql:latest
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: root
myMc3:
image: mc3-v3:3.0
ports:
- 9001:9000
links:
- mySql
environment:
runMode: dev
myElastic:
image: elasticsearch:2.4.0
ports:
- 9200:9200
You can also specify the link with an alias like so:
...
myMc3:
image: mc3-v3:3.0
ports:
- 9001:9000
links:
- mySql:mysqldb
environment:
runMode: dev
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.