简体   繁体   中英

Share IP address between docker containers

I am running single node zookeeper docker image using below command docker run -it -p 2181:2181 --name zookeeper zookeeper . Inorder to run kafka docker image, I need to share the IP address of the zookeper docker image as ENV variable and update kafka server.properties file.

Using docker inspect, I am able to fetch the IP address of zookeeper image and pass it during docker run of kafka.

But is there any way to automatically detect and share the IP address between docker containers.

I could see some example using --link, but in the latest docker documentation it seems deprecated.

Appreciate any suggestion/help

Thanks

Docker Compose is a perfect solution for your case.

By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

The docker-compose.yaml is something like below one for your case:

version: '3'
services:
  zookeeper:
    image: <zookeeper_image_name>
    restart: always
    ports:
      - 2181:2181
  kafka:
    image: <kafka_image_name>
    restart: always

Kafka container should have zookeeper as a zookeeper hostname in server.properties file.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM