Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker : How to find the network my container is in?

I am trying to understand few things about Docker:

  1. How can I find the network my container is in ?
  2. Can I dynamically detach my container and attach on an other network ? How?
  3. If I have two containers running, how to check if the two are in the same network ? Can I ping one from other ?
like image 807
theCode Avatar asked May 11 '17 00:05

theCode


1 Answers

To see what network(s) your container is on, assuming your container is called c1:

$ docker inspect c1 -f "{{json .NetworkSettings.Networks }}" 

To disconnect your container from the first network (assuming your first network is called test-net):

$ docker network disconnect test-net c1 

Then to reconnect it to another network (assuming it's called test-net-2):

$ docker network connect test-net-2 c1 

To check if two containers (or more) are on a network together:

$ docker network inspect test-net -f "{{json .Containers }}" 
like image 192
johnharris85 Avatar answered Sep 19 '22 06:09

johnharris85