How to pass the result of a command to docker inspect format (Golang template)?

I’m trying to pass the result of a command to the golang template of another command:

container_id=$(docker ps -aqf “name=container_name“)

  • docker compose won't mount the external volume
  • Running out of inodes on a docker volume
  • Spotify docker-gc: prevent auto stop after first run
  • ELK process multiline logs from multiple docker images
  • Can not connect to elasticsearch container in docker
  • ADD command not working Docker
  • docker network inspectformat='{{range $i,$container:= .Containers}} {{if eq $container.Name (print ‘gateway_’ $container_id)}} {{$container.IPv4Address}} {{end}} {{end}}’ network

    The purpose is to get the container IP Address in the specific network interface, which is not available with a simple

    docker inspect container_id

    Thank you for any help.

  • docker push gives Failed to upload
  • What is the difference of docker and in ubuntu apt repository?
  • run apps using audio in a docker container
  • Running Scrapy in Docker Container
  • Errno::EACCES creating rails project using Docker Rails image
  • Elastic Beanstalk Docker images failing to pull
  • One Solution collect form web for “How to pass the result of a command to docker inspect format (Golang template)?”

    You need to use " and escape all other $ used by golang template. The following command will print IPv4 Address by container name on interface bridge:

    $> export CONTAINER_NAME=backstabbing_feynman
    $> docker network inspect --format="{{range \$id, \$container := .Containers}} {{if eq \$container.Name \"$CONTAINER_NAME\"}} {{\$id}} -> {{\$container.IPv4Address}} {{end}}{{end}}"  bridge
    3a77b8fe2d14fb527a8c634fdaa46121672daf827c7fad0aabad1de37877e03e ->

    Using container_id will be the similiar.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.