管理数据

将数据从宿主机挂载到容器中的三种方式

  • volumes

    • Volumes are stored in a part of the host filesystem which is managed by Docker (/var/lib/docker/volumes/ on Linux). Non-Docker processes should not modify this part of the filesystem. Volumes are the best way to persist data in Docker.

  • bind mounts

    • Bind mounts may be stored anywhere on the host system. They may even be important system files or directories. Non-Docker processes on the Docker host or a Docker container can modify them at any time.

  • tmpfs

    • tmpfs mounts are stored in the host system’s memory only, and are never written to the host system’s filesystem.

the data lives on the Docker host

volume

查看数据卷

创建数据卷

查看数据卷详细信息

删除数据卷

挂载案例演示

circle-check

bind-mounts

挂在案例演示

circle-exclamation

综合案例

基于Nginx启动一个容器,监听80和81端口,访问80出现nginx默认首页,访问81,出现另外一个站点(站点数据在宿主机上的 /mnt/ 目录,容器中网站目录为 /tmp )

在宿主机与容器之间拷贝文件

Last updated