Docker - For Beginner Part 5

Docker - For Beginner Part 5

Basic Terminologies In Docker

Docker Volume :

A volume is a persistent storage location that exists outside of the container.
Useful for storing data that needs to persist even if the container is stopped or removed.
You can share the volume.

How to create the Volume:

#To create the volume
docker volume create <volumename>
#To list the volume
docker volume list
#To inspect the volum
docker volume inspect [volume_name]

Volume Creating Strategies

  1. Sharing Volume From The Host :
    In this volume-sharing strategy, the volume of the Host machine i.e. server is shared with the container.

     #docker run -ti --name <nameofcontainer> <pathofsource>:<pathofdestination> --privileged=true <baseimage> /bin/bash
     docker run -ti --name MyTestContainer /root/Data/:/tmp/Data/ --privileged=true ubuntu /bin/bash
    
  2. Sharing Volume From The Container :
    In this volume-sharing strategy, the volume of the container / created volume in the docker host is shared.

     #Create a container with volume
     #docker run -ti --name <nameofcontainer> -v <pathofsource> <baseimage> /bin/bash
     docker run -ti --name Container1 -v /root/Data/ubuntu /bin/bash
    
     #Connection between Container1 and Container2
     #docker run -ti --name <nameofcontainer> -v <pathofsource>:<pathofdestination> --privileged=true --volumes-from <containername> <baseimage> /bin/bash
     docker run -ti --name Container2 -v /root/Data/:/tmp/Data/ --privileged=true --volumes-from Container1 ubuntu /bin/bash
    
  3. Sharing Volume From Docker File :
    In this volume-sharing strategy, the volume is created using the docker file which creates in the docker image and can be used in a docker container.

     FROM ubuntu
     VOLUME ["/root/myvolume"]
    

Docker Expose :

It is used for accessing the container from outside of the container.
It accesses container to container.

#docker run -it --name <nameofcontainer> -p <portfrominside>:<portfromoutside> <base_imagname> /bin/bash
docker run -it --name Container1 -p 80:80 ubuntu /bin/bash
#To check port connected to container
dokcer port <containername>
FROM ubuntu
EXPOSE 80

Docker Diff :

This command is used to get the difference between the base image and the currently used image.

docker diff <containerid> <containerid>

Output
A – A file or directory was added
D – A file or directory was deleted
C – A file or directory was changed

Docker Network :

Docker networking is primarily used to establish communication between Docker containers and the outside world via the host machine where the Docker daemon is running.

Docker Network Types:

  1. Bridge Network
    Bridge networking is the most common network type. It is limited to containers within a single host running the Docker engine. Bridge networks are easy to create, manage and troubleshoot.

     $ docker network create -d bridge my-bridge-net
    
     #inspect the bridge
     docker network inspect
    
  2. Overlay Network:
    An overlay network uses software virtualization to create additional layers of network abstraction running on top of a physical network.
    In Docker, an overlay network driver is used for multi-host network communication. This driver utilizes Virtual Extensible LAN (VXLAN) technology which provides portability between cloud, on-premise and virtual environments.
    VXLAN solves common portability limitations by extending layer 2 subnets across layer 3 network boundaries, hence containers can run on foreign IP subnets.

     $ docker network create -d overlay --subnet=<IPaddress>/24 my-overlay-net