Answers: <p>The <code>docker network inspect</code> command produces a JSON output that can be parsed using <a href="https://stedolan.github.io/jq/" rel="nofollow noreferrer"><code>jq</code></a> to extract the relevant piece of information:</p>
  
  <pre><code>sudo docker network inspect app-bridge | jq '.[].Containers[].Name'
  
  "app2"
  "app3"
  "app1"
  "laughing_easley"
  "database"
  "thirsty_wing"
  </code></pre>
  
  <p>If you are already familiar with JSON processing with <code>jq</code>, the advantage is you can reinvest your knowledge without having to bother with <a href="https://golang.org/pkg/text/template/" rel="nofollow noreferrer">Go templates</a>. On the other hand, it relies on an external tool which may or may be not available at your site.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-31T17:17:07.103Z
Answers: 2019-02-01T10:00:21.907Z
Answers: 2019-02-01T10:00:21.907Z
Answers: Sylvain Leroux
Body: <p>I'm reworking a bunch of scripts using the deprecated <code>docker run --link</code> option in favor of user-defined bridges.</p>
  
  <p>By searching in the doc, I didn't find any command to list all containers attached to a given network. For now, I am parsing the JSON output of <a href="https://docs.docker.com/engine/reference/commandline/network_inspect/" rel="nofollow noreferrer"><code>docker network inspect</code></a> through the <code>jq</code> tool; I've posted that as an answer below since it may help someone. But, do you know another option to achieve that? Maybe using a dedicated Docker command, option or a custom Go format?</p>
  
Tags: <docker>
Title: How to list the containers attached to a given user-defined network?
UserDisplayName: Sylvain Leroux
ThreadText: # How to list the containers attached to a given user-defined network?
  
  (Asked by: username_0 on 2019-01-31)
  
  I'm reworking a bunch of scripts using the deprecated `docker run --link` option in favor of user-defined bridges.
  
  By searching in the doc, I didn't find any command to list all containers attached to a given network. For now, I am parsing the JSON output of [`docker network inspect`](https://docs.docker.com/engine/reference/commandline/network_inspect/) through the `jq` tool; I've posted that as an answer below since it may help someone. But, do you know another option to achieve that? Maybe using a dedicated Docker command, option or a custom Go format?
  
  **Tags:** docker
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-01-31. Score: 1 | Accepted answer
  
  The `docker network inspect` command produces a JSON output that can be parsed using [`jq`](https://stedolan.github.io/jq/) to extract the relevant piece of information:
  
  ```
  sudo docker network inspect app-bridge | jq '.[].Containers[].Name'
  
  "app2"
  "app3"
  "app1"
  "laughing_easley"
  "database"
  "thirsty_wing"
  
  ```
  
  If you are already familiar with JSON processing with `jq`, the advantage is you can reinvest your knowledge without having to bother with [Go templates](https://golang.org/pkg/text/template/). On the other hand, it relies on an external tool which may or may be not available at your site.
  
  
  ---
  
  