-
For example Container (Nginx) is running -- this nginx container will continously puts information about login info like IP address and other info and tries to store in a log file.
-
This logfile is imp, For security checks and last 10 days depending on the organization, time to time you perform auditing.
-
For suppose the container gone down, Because of container gone down, The log file will be deleted.
-
Containers are ephemeral or shortlived in nature
-
Container should not have a file system in nature
If container goes down, It used all of the resouces from host OS, but they are not a permanetly resources
for this container, If container goes down they free up the resources from OS and killed now the user details or the logfile of the nginx is deleted.
Example we have 2 containers 1 is front-end and 2nd is backend, The backend container will producer or sends
html file to front end -- suddenly if backend container goes down then the generated files like today's yesterday's or 10 ago or one month ago files will be not available to front and front will only show which are available like today's yesterdays files. Since we are not using persistence storage the information will be available.
Assume we have one application, The whole purpose of the application is to read some file which is not on our
container, container reads the file that is provided from a CRON JOB on the HOST OS
- It allows to Bind a directory inside the container
- It will bind a floder on our container with folder on the HOST
- Any folder that is /app folder can be read the container, Container will read or write to that specific dir
- If the container goes down, The /app dir is also present in the HOST when ever a new container comes up called C2 now again bind the same /app folder, So that the information is not lost, Whenever container is come up it already has the information
- Even if container is not coming up the user information or whatever data is present in the HOST will be available.
Volumes also do some job, But have a better life cycle
- Use docker cli we can use volumes, Volumes are nothing logical partition that we are creating in the HOST
- Create, destory, attach, attach the same volume to one more containers
- Attaching specific folder or a specific file sytem to a container, But he main advantage is we are not providing dir details like /app dir, Instead we are saying create a volume on the HOST
- This volume basically a logically partition on a HOSTd
- Logical volume will be mounted to the conatiner
- We are managing the entire volumes using docker cli it self.
- If we are using bind mounts then we are restricted to use only that particular dir, But if we are using volumes, we can create volume on any place like same HOST, External EC2 instance, any external storage devices like S3 buckets or NFS not restriction we have lot of options, externnal sources
- Like bind mounts, we don't have to play directly use with the when container is running, Instead we can manage it life cycle by docker commands
- Docker docker volume, docker volumes ls -- commands
- This volumes can easily shared from one container to other container
- This volumes can be high performance as well
- docker -v == If we are using -v that means we define the arguments like source; dest; temp ;parmanent storeage;
- docker --mount == Detailed commadnd like source == source 2.1) storage == storage 2.2) etc
- The above 1 and 2 commands are same just syntax is different.
- List volumes
sudo docker volume ls
- Create volume
sudo docker volume create pavan
- Details of specific volume and where it is stored exactly
sudo docker volume inspect pavan
- To delete a volume
sudo docker volume rm pavan
-- 1st stop the container and delete the container they only we can delete volume. 5) To print 1st first docker images
sudo docker images | head -5
- To mount volume to the container
sudo docker run -d --mount source=pavan,target=/app volumedemofile
We can add additional parameters as well by using ',' like mode="mount","RW=false", and etc
Here pavan -- volume created
volumedemofile -- docker image
- To check volume is mounted or not
sudo docker insepct <contianer-id>
Ex:
"Mounts": [
{
"Type": "volume",
"Name": "pavan",
"Source": "/var/lib/docker/volumes/pavan/_data",
"Destination": "/app",
"Driver": "local",
"Mode": "z",
"RW": true,
"Propagation": ""
}
],