Docker Volume Plugin Development and Golang implementation

Source: Internet
Author: User
Tags docker compose

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.