容器與host共享數(shù)據(jù)
容器之間共享數(shù)據(jù)
volume container
data-packed volume container
volume container的數(shù)據(jù)歸根到底還是在host里,有木有辦法將數(shù)據(jù)完全放到volume container中,同事又能與其他容器共享呢?
當(dāng)然可以,通常我們稱這種容器為data-packed volume container.其原理是將數(shù)據(jù)打包到鏡像中,然后通過docker managed volume共享
我們用下面的Dockfile構(gòu)建鏡像:
From busybox:latest
ADD htdocs /usr/local/apache2/htdocs
VOLUME /usr/local/apache2/htdocs
Add將靜態(tài)文件添加到容器目錄/usr/local/apache2/htdocs
VOLUME的作用與-v等效,用來創(chuàng)建docker managed volume,mount point為/usr/local/apache2/htdocs,因為這個目錄就是ADD添加的目錄,所以將已有數(shù)據(jù)拷貝到volume中。