企业网站建站企业,六安短视频优化费用,wordpress 作者调用,怎么创造免费网站卷是为Docker容器保留数据的首选方法。在本文中#xff0c;将展示如何创建和使用卷来实现持久性#xff0c;以及如何使用tmpfs来实现临时存储。最简单的说#xff0c;创建和安装由本地目录支持的卷如下所示#xff1a;# make host directory
mkdir -p /data# create docker… 卷是为Docker容器保留数据的首选方法。在本文中将展示如何创建和使用卷来实现持久性以及如何使用tmpfs来实现临时存储。最简单的说创建和安装由本地目录支持的卷如下所示# make host directory
mkdir -p /data# create docker volume from host directory
sudo docker volume create --driver local --opt typenone --opt device/data --opt obind --nametest# mount volume within container
sudo docker run -it --mount sourcetest,target/mymount alpine:latest /bin/df -h /mymount卷安装现在让我们看一个具体的示例其中有一个运行Apache2的容器该容器从其Web根传递内容。在github上创建了一个名为fabianlee / alpine-voltest的项目并将其推送到docker hub。该Dockerfile很小仅扩展了alpine-apache映像然后通过在从容器提供Web内容的目录中添加一个卷将其进一步扩展了。FROM fabianlee/alpine-apache:2.4.41-r0
...
VOLUME /var/www/localhost/htdocs/让已打包好的状态运行容器不装入任何卷。sudo docker run -d --rm --name alpine-voltest -p 8080:80 fabianlee/alpine-voltest:1.0.0打开本地Docker主机上的浏览器端口8080。返回的内容是放置在“ / var / www / localhost / htdocs”目录中的容器上的默认index.html。继续并立即停止容器。sudo docker stop alpine-voltest但是如果将本地卷安装到该容器目录则可以控制该卷从该Web服务器传递的内容。# create local host content
sudo mkdir -p /data/test
echo h1This is mounted on the docker host at /data/test/index.html/h1 | sudo tee /data/test/index.html# create docker volume from host directory
sudo docker volume create --driver local --opt typenone --opt device/data/test --opt obind --nametest# volume details
sudo docker volume inspect test# create container that uses test volume, mounts at web root
sudo docker run -d --rm --name alpine-voltest -p 8080:80 --mount sourcetest,target/var/www/localhost/htdocs fabianlee/alpine-voltest:1.0.0现在浏览器将返回以下内容即我们放入本地docker主机文件“ /data/test/index.html”中的内容。再次停止容器。sudo docker stop alpine-voltest# list volumes
sudo docker volume ls即使容器停止后这些文件仍保留在主机上以后的容器实例也可以重新挂载该卷。初始数量人口如果使用不存在的卷名启动容器则将创建一个新的卷。此外如果主机目录完全为空则容器的内容将填充复制到本地主机卷目录中。# start container, allow it to create volume and populate
sudo docker run -d --rm --name alpine-voltest -p 8080:80 --mount sourcenewtest,target/var/www/localhost/htdocs fabianlee/alpine-voltest:1.0.0# volume details
sudo docker inspect newtest | grep -i Mountpoint# get list of files in new volume (should now contain index.html)
sudo ls -l /dockerhome/volumes/newtest/_data# stop container
sudo docker stop alpine-voltest# data still persists, but can be deleted
sudo docker system prune
sudo docker volume prune临时文件系统对于只能由单个容器使用的小型临时存储空间有tmpfs文件系统。它仅由主机系统上的RAM存储支持。创建安装在/ tempdisk的2Mb临时磁盘空间创建安装在/ tempdisk的4Mb tmpfs空间然后将文件写入