Home  >  Q&A  >  body text

宿主机上如何获得 docker container 容器的 ip 地址?

docker 宿主机与容器 container 需要进行一些文件同步操作,需要获取 container 容器的 ip 地址,应该怎么获得呢?

怪我咯怪我咯2710 days ago978

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-21 10:59:03

    docker inspect --format='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID

    reply
    0
  • PHP中文网

    PHP中文网2017-04-21 10:59:03

    The IP of the container will change every time it is started, so knowing the IP of the container is meaningless.
    For file synchronization operations, why not mount it to the host through -v?

    docker exec CID ifconfig
    If the container has ifconfig

    reply
    0
  • 怪我咯

    怪我咯2017-04-21 10:59:03

    Very simple docker inspect container ID | grep IP

    reply
    0
  • Cancelreply