0% found this document useful (0 votes)
262 views

Docker - Networking and Volumes

This document discusses Docker networking and volumes. It provides examples of Docker network and volume commands. For networking, it demonstrates creating a bridge network, connecting and disconnecting containers from networks, and removing networks. For volumes, it shows creating and removing volumes, mounting volumes into containers for data persistence, and using bind mounts from the host filesystem.

Uploaded by

VP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
262 views

Docker - Networking and Volumes

This document discusses Docker networking and volumes. It provides examples of Docker network and volume commands. For networking, it demonstrates creating a bridge network, connecting and disconnecting containers from networks, and removing networks. For volumes, it shows creating and removing volumes, mounting volumes into containers for data persistence, and using bind mounts from the host filesystem.

Uploaded by

VP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Host Network

Bridge Network None Network


docker run ubuntu --network = host
docker run ubuntu docker run ubuntu --network=none

8080 8080
Web Web Web Web
Container Container Container Container

172.17.0.2 172.17.0.3

172.17.0.0 Web
172.17.0.6
Container
172.17.0.4

Web Web
Container Container

Docker host Docker host Docker host


container 1
container 2
Network
namespace
Network
namespace

Bridge
(docker0)

Docker host
Web Web
Container Container
172.17.0.3 182.17.0.3

172.17.0.0 182.17.0.0

172.17.0.6 182.17.0.6

Web Web
Container Container

Docker host
Docker Network Commands
1. docker network ls
2. docker network create --driver=bridge --subnet=192.168.1.0/24
<net_name>
3. docker container run –itd –name=<name> --net=codificationNet ubuntu
4. docker network inspect <network id>
5. docker network connect custom-net my-container
6. docker network disconnect custom-net my-container
7. docker network rm custom-net
8. docker network prune
Container Layer
(Writable Layer)

Docker Image Layer


(Read-only Layer)
Read Write
/var/lib/mysql

/var/libs/docker/volumes

Read-only
mysql – image layer

Docker Host
Docker Volume Commands
1. docker volume ls
2. docker volume create data_volume
3. docker run –v data_volume:/var/lib/mysql mysql (Volume mount)
4. docker run -v /data/mysql:/var/lib/mysql mysql (Bind Mount)
5. docker run --mount type=bind,source=/data/mysql,target=/var/lib/mysql
mysql
6. docker volume remove data_volume
7. docker volume prune
8. Read-only mounts – docker container run --mount source=data_volume,
desitnation=/var/lib/data,readonly httpd

You might also like