How to get ENV variable when doing Docker Inspect

前端 未结 8 1255
鱼传尺愫
鱼传尺愫 2020-11-30 05:12

I wonder how I get an Environment variable from docker inspect.

when i run

docker inspect -f \"{{.Config.Env.PATH}} \" 1e2b8689cf06
相关标签:
8条回答
  • 2020-11-30 05:36

    A very convenient option that doesn't require any external tools is:

    docker exec 1e2b8689cf06 sh -c 'echo $PATH'
    

    Admittedly this is not using docker inspect, but still..

    0 讨论(0)
  • 2020-11-30 05:41

    I find it better to parse for the environment variable name your interested than relying on index.

    echo $(docker inspect --format '{{ .Config.Env }}' mysql) |  tr ' ' '\n' | grep MYSQL_ROOT_PASSWORD | sed 's/^.*=//'
    
    0 讨论(0)
提交回复
热议问题