How Containers Work
- Refer Here
- Cgroups


Docker Image Layers and Containers
- Every container created has one R/W Layer added
- All the changes made by container are in R/W layer

- When we delete the container the R/W layer will be deleted where as the image (i.e. image layers stay in tact)
- The data that is generated by the container (i.e. running application) will be lost if we delete the container.
- Now lets assume we have created mysql in a container. All the db updates will be present in the Thin R/W layer and if we delete mysql contaier we loose all the changes i.e. we loose data
- We need to have some way to preserve this data created by containers i.e. life time of the data should be independent of the container.
- Refer Here for image layers & Refer Here for the concept of the impact of image layers
- To preserve the data loss in the Thin R/W layer of a container docker has a concept of volumes
Docker Volumes
- Lets create a nginx container

- Create some files

- Now Remove the container

- The data created is lost
- To persist the data created by container in the Docker Host Docker has volumes
- For managing volumes docker has
docker volumesubcommand

- Now lets create a volume

- Now lets create nginx container and attach this volume. Add some data

- Remove the container and inspect volume


- Even after removing the container the data is not lost
- Now lets create a new container by attaching the same volume

- We can use this volume to attach multiple containers and share it across containers

- Refer Here for the concept of docker volumes.
