How to get the mapped port on host from a docker container?

前端 未结 3 1820
南方客
南方客 2021-02-02 15:59

I want to run a task in some docker containers on different hosts. And I have written a manager app to manage the containers(start task, stop task, get status, etc...) . Once a

3条回答
  •  借酒劲吻你
    2021-02-02 16:16

    i share /var/run/docker.sock to container and get self info

    docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock alpine:latest sh
    

    in container shell

    env //get HOSTNAME
    
    curl --unix-socket /var/run/docker.sock http://localhost/containers/3c6b9e44a622/json
    

    the 3c6b9e44a622 is your HOSTNAME

提交回复
热议问题