我下面有docker-compose yml示例
version: '3'
services:
spark-master:
image: bde2020/spark-master:2.4.4-hadoop2.7
container_name: spark-master
ports:
- "8080:8080"
- "7077:7077"
environment:
- INIT_DAEMON_STEP=setup_spark
spark-worker-1:
image: bde2020/spark-worker:2.4.4-hadoop2.7
container_name: spark-worker-1
depends_on:
- spark-master
ports:
- "8081:8081"
environment:
- "SPARK_MASTER=spark://spark-master:7077"
- SPARK_CONTAINDER_IP = **here i want the ip address of above spark master**
有可能吗?谁能帮助我
更新:,我们可以使用以下命令获取容器ID
docker ps --format "{{.ID}}" --filter "dockerhost"
但不能使用此命令返回值并将其分配给环境变量
答案 0 :(得分:0)
正如我在评论中所说:
您的另一个撰写工作正常,也许您的工作人员开始得更快 比您的主人高,因此您会获得例外,请参阅 docs.docker.com/compose/startup-order
其他解决方案可能是在服务中使用固定IP地址:
myservice:
container_name: mycon
image: some:image
networks:
mynet:
ipv4_address: 172.28.1.10
networks:
mynet:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16