Sunday, July 11, 2021

Docker networking


Create bridge

docker network create -d bridge mars_bridge


Run container inside specific network (i.e. Redis and Redis CLI)

docker run --name some-redis --network mars_bridge --rm -d redis

docker run -it --network mars_bridge --rm redis redis-cli -h some-redis


Connect container to network

docker network connect mars_bridge some-redis


Disconnect container from network

docker network disconnect mars_bridge some-redis


List Docker networks

docker network ls


Remove Docker network

docker network rm mars_bridge


Remove all unused networks

docker network prune


Inspect Docker network

docker network inspect mars_bridge


Inspect with formatted output

docker inspect --format='{{json .NetworkSettings.Networks}}'  some-redis

docker inspect --format="{{json .NetworkSettings.Networks}}" some-redis

docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" some-redis


Sources

Docker - networking containers

Docker Hub - Redis (as an example of Docker-networked container)


No comments: