Docker Volume and Network
Docker Volume
Docker volume is simply a directory inside container or a persistence storage volume in container.
Volume will be create, when you create a container.
We can share a volume with other container also.
Volume can be mapped/share in two ways
- Container to Container
- Host to Container
Docker Network
Docker Network is used establish communication between containers and host machine.
Docker network can be created automatically and manually.
Docker contains mainly three types of network.
- Bridge – default network
- Host – can be created or for standalone container
- Null – null or none can be used for not to provide communication to container
Docker Volume Commands
To List a Volumes
$ sudo docker volume ls
To Create a Volume
$ sudo docker volume create <volume-name>
To get Information about Volume
$ sudo docker volume inspect <volume-name>
Example:-
To Mount Volume to a Container
$ sudo docker run –mount source=[volume_name],destination=[path_in_container] [docker_image_name]
To Run a Container and mount a volume then use this command
$ sudo docker run -it –name=sredient –mount source=<volume-name>,destination=/<volume-name> <image-name>
Example:-
To Share volume from Host to container
$ sudo docker run -it –name=sredient –mount source=<volume-name or volume-path>,destination=/<volume-name> <image-name>
To Remove Volumes
$ sudo docker rm <volume-name>
To Remove all Unused volumes
$ sudo docker prune
Docker Network Commands
To List a networks
$ sudo docker network ls
To know more opetions
$ sudo docker network –help
To connect a container to a network
$ sudo docker connect <network-id/name> <container-id>
To disconnect from a network
$ sudo docker disconnect <network-id/name> <container-id>
To create a network
$ sudo docker network create -d <network-type> <network name>
To know more about Create Command
$ sudo docker network create –help
To remove Network
$ sudo docker network rm