[英]how to get and set the ip address of one container in another docker image config?
I have below sample docker-compose yml我有以下示例 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**
is it possible?是否可以? can anyone please help me
谁能帮帮我吗
Update : we can get container ID using below command更新:我们可以使用以下命令获取容器 ID
docker ps --format "{{.ID}}" --filter "dockerhost"
but am not getting use this command return values and assign it to environment variable但我没有使用此命令返回值并将其分配给环境变量
as I said in the comments:正如我在评论中所说:
your another compose works just fine, maybe your worker started faster than your master therefore you get the exceptions , see docs.docker.com/compose/startup-order
你的另一个 compose 工作得很好,也许你的工人比你的主人开始得更快,因此你得到了例外,请参阅 docs.docker.com/compose/startup-order
other solution could be use fix IP adresses in your compose for your services:其他解决方案可能是在您的服务中使用修复 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.