Original address: http://www.damonyi.cc/?p=232
Pre-project requirements, the need to make reasonable use of the host storage, the use of the host deployment agent, the way to achieve the allocation of Docker data volume based on LVM, with the development of the project to integrate Docker compose to complete the application of automatic orchestration, need in the Docker Creating a data volume for a container in compose and specifying the volume size, the previous mode of using the agent has been unable to meet the current requirements. Refer to the Docker official documentation and Local-persist project to implement an LVM-based volume plug-in DOCKER-VOLUME-PLUGIN-LVM.
Docker Volume Plugin provides a standard volume management API that only the third party can implement with these APIs.
Plug-in loading mode, the implementation of their own driver registration, start the main function, actually started a listening port, sock file:/var/run/docker/plugins/lvm.sock
Func Main () {
Driver: = Newlvmpersistdriver ()
Handler: = volume. Newhandler (Driver)
FMT. Println (handler. Serveunix ("root", driver. Name)
}
Querying the Volume API:
Func (Driver *lvmpersistdriver) Get (req volume. Request) volume. Response
Create Volume API: Take the volume name and volume size according to the parameters of the entry, assign the LV in the LVM VG, and persist the volume's metadata to memory, and if you do not set the volume size, you can set the default value (currently only modified by code) PS: When you create a container using the Docker create command, Unable to specify volume size comparison pit, fortunately Docker compose support
Func (Driver *lvmpersistdriver) Create (req volume. Request) volume. Response
Mount Volume API: Gets the volume name based on the entry parameter, verifies that the volume already exists, if present, formats the LV and mounts it to the host directory (the host directory is specified by the volume plug-in) (if the host directory is already mounted, do not perform this step), the mount point, that is, the host directory to volume. Response way back, PS: Support multiple containers to mount the same data volume, but the read and write control is not implemented, need to container own control.
Func (Driver *lvmpersistdriver) Mount (req volume. Request) volume. Response
To unmount the volume API:
Func (Driver *lvmpersistdriver) unmount (req volume. Request) volume. Response
To delete a volume API:
Func (Driver *lvmpersistdriver) Remove (req volume. Request) volume. Response
The implementation can refer to the code implementation. Docker-volume-plugin-lvm
The code is not perfect at the moment, test the code, and the deployment run code is not implemented yet. I am more lazy ...
Original address: http://www.damonyi.cc/?p=232
The original source and this statement must be indicated in the form of a link when reproduced.