We can create volumn to keep the data, even we stop the container and restart again, the data won't get lost.

To create a link between the folder /my-files on your host machine and the htdocs folder in the container. This also runs the container in the background.

docker run -d -p : -v /my-files:/usr/local/apache2/htdocs web-server:1.1

After runnning the container, Let’s see what this looks like from inside the container.

Attache a shell to the container:

docker container exec -it elegant_noether /bin/bash

cd to folder:

cd /usr/local/apache2/htdocs

Now we can use 'ls -la' to see what is inside the folder.


Examples:

// Create a Volume named "webdata"
docker volume create --name webdata // Run a container points to "webdata" we just created
docker run -d --name web1 -v webdata:/usr/share/nginx/html -p :/ nginx // Change index.html thought
docker exec web1 bash -c 'echo "foo" > /usr/share/nginx/html/index.html' // you can check the index.html
curl localhost: // Now let's remove the container
docker stop web1
docker rm web1 // Verify there is no running container
docker ps -a // Create a new container with the same name as before
docker run -d --name web1 -v webdata:/usr/share/nginx/html/index.html -p : nginx // Chceck the data again
curl localhost: // And we can see that it prints out "foo" // We can export the same file to other container
docker run -d --name web2 -v webdata:/usr/share/nginx/html/index.html -p : nginx // Check the index.html file on web2
curl localhost: // And we can see it prints out "foo" too // Change the volume on one of the container
docker exec web1 bash -c 'echo "bar" > /usr/sgare/nginx/html/index.html' // And we can see both container's data changed
curl localhost:
curl lcoalhost: // To remove a volume, we need to stop all the containers
docker stop web1 web2 && docker rm web1 web2
docker volume rm webdata // Verify the volume was removed
docker volume ls

If you want to chck whether there is a volume inside a container:

docker inspect -f '{{.Mounts}}' web1

Inspect volume itself:

docker volume inspect webdata

[Docker] Create a Volume的更多相关文章

  1. (转)Docker volume plugin - enabled create local volume on docker host

    原文地址:https://hub.docker.com/r/cwspear/docker-local-persist-volume-plugin/ Short Description Create n ...

  2. [转帖]Docker的数据管理(volume/bind mount/tmpfs)

    Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs) https://www.cnblogs.com/zhuochong/p/10069719.html do ...

  3. [Docker] Hooking a Volume to Node.js Source Code

    Normally when you create a Volume, it will store in Docket Host, you can also tell the folder which ...

  4. Docker学习之volume

    提供独立于容器之外的持久化存储 容器中的数据会随着容器的消失而消失,为了解决这个问题,产生了数据卷volume. 例子,比如说mysql容器,msyql中的数据应该是持久化的,故应该存储在volume ...

  5. 解决 Windows Docker 安装 Gitlab Volume 权限问题

    本文首发于我的个人博客,解决 Windows Docker 安装 Gitlab Volume 权限问题 ,欢迎访问! 记录一下 Windows10 下 Docker 安装 Gitlab 的步骤. Ca ...

  6. Docker数据卷Volume实现文件共享、数据迁移备份(三)

    数据卷volume功能特性 数据卷 是一个可供一个或多个容器使用的特殊目录,实现让容器中的一个目录和宿主机中的一个文件或者目录进行绑定.数据卷 是被设计用来持久化数据的对于数据卷你可以理解为NFS中的 ...

  7. Docker(10)- docker create 命令详解

    如果你还想从头学起 Docker,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1870863.html 作用 创建一个新的容器但不启动它 ...

  8. Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs)

    Docker提供了三种不同的方式用于将宿主的数据挂载到容器中:volumes,bind mounts,tmpfs volumes.当你不知道该选择哪种方式时,记住,volumes总是正确的选择. vo ...

  9. [Docker] Create Docker Volumes for Persistent Storage

    Docker containers are stateless by default. In order to persist filesystem changes, you must use doc ...

随机推荐

  1. Android自定义系统分享面板

    在Android中实现分享有一种比较方便的方式,调用系统的分享面板来分享我们的应用.最基本的实现如下: public Intent getShareIntent(){ Intent intent = ...

  2. Android 通过局域网udp广播自动建立socket连接

    Android开发中经常会用到socket通讯.由于项目需要,最近研究了一下这方面的知识. 需求是想通过wifi实现android移动设备和android平台的电视之间的文件传输与控制. 毫无疑问这中 ...

  3. IDFA和IMEI

    这里有一些解释: https://www.zhihu.com/question/38856446

  4. 一起talk C栗子吧(第九十 三回:C语言实例--进程间通信之临界资源)

    各位看官们.大家好,前面章回中咱们说的是使用信号和管道进行进程间通信的样例.这一回咱们说的样例是:进程间通信之临界资源.闲话休提,言归正转.让我们一起talk C栗子吧! 我们首先介绍一下,什么是临界 ...

  5. HTML基础第六讲---表格

    转自:https://i.cnblogs.com/posts?categoryid=1121494 上一讲,讲了关于<控制表格及其表项的对齐方式>,在这里我要讲讲表格及其属性 ,然后大家在 ...

  6. vue 自定义modal 模态框组件

    参数名 类型 说明 visible Boolean 是否显示,默认false title String 标题 update:visible Boolean 更新visible, 使用:visible. ...

  7. solr6.3+tomcat8报错HTTP Status 403 – Forbidden解决办法

    注释掉tomcat下solr项目web.xml中的如下这段代码即可:

  8. 【CS Round #43 B】Rectangle Partition

    [链接]https://csacademy.com/contest/round-43/task/rectangle-partition/ [题意] 水题 [题解] 横着过去,把相邻的边的宽记录下来. ...

  9. NYOJ 552 小数阶乘

    小数阶乘 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描写叙述 编写一个程序,求一个数m的阶乘. 输入 有多组測试数据,以EOF结束. 每组測试数据有1个整数m. 输出 每 ...

  10. CSS笔记 - fgm练习 - 鼠标移入移出div显示隐藏 CSS样式部分

    问题总结: 1. checkbox和下面隐藏的div对齐,是在清除了默认样式的前提下,而不需要额外设置float: left; 2. 隐藏的div这里不需要专门设置宽高.居中,是靠内容和padding ...