简体   繁体   English

如何在另一个docker镜像配置中获取和设置一个容器的IP地址?

[英]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.

相关问题 一个 Docker Container 如何找到另一个 Docker Container 的 IP 地址? - How can one Docker Container find the IP address of another Docker Container? 如何获取正在运行的docker容器的IP地址 - How to get IP address of running docker container 如何将Docker容器的IP地址动态映射到另一个容器 - How to map the IP address of docker container to another container dynamically 具有多个网络接口的Docker容器:只获取一个IP地址 - Docker container with multiple network interfaces: get only one IP address 如何获取从另一个容器(Docker Compose)运行的RabbitMQ的IP地址? - How can I get the IP address of RabbitMQ running from another container (Docker Compose)? 如何使用docker-compose为容器设置固定的IP地址? - How to set fixed ip address for container using docker-compose? 如何在Docker容器中设置静态IP地址? - How can I set a static IP address in a Docker container? 如何从docker容器中获取mac主机IP地址? - How to get mac host IP address from a docker container? maven-docker-plugin:如何获取容器ip地址 - maven-docker-plugin: how to get container ip address 如何在docker-compse中获取容器的IP地址 - How to get IP address of container in docker-compse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM