Whether the data in the docker container will be lost
This article is to share with you about whether the data in the docker container will be lost. Xiaobian thinks it is quite practical, so share it with you to learn. I hope you can gain something after reading this article. Let's not say much. Let's take a look at it together with Xiaobian.
Will the docker container lose data? There are two ways to persist data in docker containers. (1) Reverse container to mirror image by commit command;(2) Pull data out of container data volume.
The role of container data volume is to persist container data, inherit and share data among containers.
A volume is a directory or file that exists in one or more containers, intercepted by Docker to the container, but is not part of a federated file system, so it can bypass federated file systems to provide some features for persistent storage or sharing of data.
Volumes are designed to persist data independently of the container lifecycle, so Docker does not delete mounted volumes when a container is deleted. The volume persists, even if the container on which the data volume is mounted has been deleted.
Container How to add data volumes
1) Command added
docker run -it -v host absolute path directory: directory in container [:ro] image name
:ro Forcing read-only permissions to be added to this container for shared directories, i.e. shared directories in the container are read-only
-privileged=true Add Shared Directory Error
2) DockerFile added
Create a DockerFile file, add one or more volumes to the image using the VOLUME command in the file, and then use docker build to make it a mirror.
Using docker run to make mirror instances containers
Use docker inspect to view shared addresses corresponding to hosts
The above is whether the data in the docker container will be lost, Xiaobian believes that some knowledge points may be what we will see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.