Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article mainly introduces the underlying data storage structure of Docker

Docker underlying storage structure

Q&A

  • Will all files in image A be copied when image B is created based on image A?The mirror is not copied or deleted, only the reference is deleted
  • When creating a container based on an image, only all files in the shared container are copied to the bottom of the container.
  • What is the structural difference between a container and an image?

The storage structure of the image

  • Viewing reference relationships
docker history ssm_nginx:latest
Copy the code
  • Store information
#Example Query all mirrors
docker images 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssm_nginx           latest              7f48053b7f39        43 minutes ago      127MB

#Example Query the details about a mirror
docker inspect 7f48053b7f39

#Image information/ / the lower "LowerDir" : "/var/lib/docker/overlay2/5dbfb6581a8882ce79c184986fb02498ee404ea775ef1bb37428455331c1f177/diff:/var/lib/docker/overlay2 /817ce2d6a40ec1c63d382c0eb647b325bd1f52d16e18c8a1f2f5643fe96de5c9/diff:/var/lib/docker/overlay2/d1fdd72104f5a8cb4796b020 Ae22a7f22e7b97f589c50452f9d704612ecdb2b2 / diff ", / / merge "MergedDir" : "/ var/lib/docker/overlay2/03876 a90f4b8874a9a7df210e1edb39f9a13e28d0b0c05ba1f7479e3c1c7cd82 / merged", / / the superior "UpperDir" : "/var/lib/docker/overlay2/03876a90f4b8874a9a7df210e1edb39f9a13e28d0b0c05ba1f7479e3c1c7cd82/diff", "WorkDir": "/var/lib/docker/overlay2/03876a90f4b8874a9a7df210e1edb39f9a13e28d0b0c05ba1f7479e3c1c7cd82/work"
## container information"LowerDir": "/var/lib/docker/overlay2/dc97629c6fc37be2a0f2a74b4786328e8bb8ebf7c2e50c8435186fe1b5ac1217-init/diff:/var/lib/docker/ove rlay2/03876a90f4b8874a9a7df210e1edb39f9a13e28d0b0c05ba1f7479e3c1c7cd82/diff:/var/lib/docker/overlay2/5dbfb6581a8882ce79c 184986fb02498ee404ea775ef1bb37428455331c1f177/diff:/var/lib/docker/overlay2/817ce2d6a40ec1c63d382c0eb647b325bd1f52d16e18 c8a1f2f5643fe96de5c9/diff:/var/lib/docker/overlay2/d1fdd72104f5a8cb4796b020ae22a7f22e7b97f589c50452f9d704612ecdb2b2/diff ", "MergedDir": (merge all layers) "/ var/lib/docker/overlay2 / dc97629c6fc37be2a0f2a74b4786328e8bb8ebf7c2e50c8435186fe1b5ac1217 / merged", "UpperDir" : (Container read-write layer, Container will create these files) during the operation of "/ var/lib/docker/overlay2 / dc97629c6fc37be2a0f2a74b4786328e8bb8ebf7c2e50c8435186fe1b5ac1217 / diff". "WorkDir": "/var/lib/docker/overlay2/dc97629c6fc37be2a0f2a74b4786328e8bb8ebf7c2e50c8435186fe1b5ac1217/work"Copy the code
  • Viewing Upper-layer Information
#Open the upper directory
cd /var/lib/docker/overlay2/03876a90f4b8874a9a7df210e1edb39f9a13e28d0b0c05ba1f7479e3c1c7cd82/diff

#View upper-layer Settings
cat usr/share/nginx/html/index.html 
<h1>This is Test Nginx</h1>
Copy the code
  • At the bottom is the file information of the operating system

The resources

  • www.runoob.com/docker/dock…
  • docker.com