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. js--递归详解

    1 函数的调用 eg1:阶乘算法 var f = function (x) { if (x === 1) { return 1; } else { return x * f(x - 1); } }; ...

  2. 自定义input[type="checkbox"]样式

    input[type=checkbox] { visibility: hidden; position: relative;} input[type=checkbox]:after { content ...

  3. 基于Lwip协议栈中独立模式下回调函数的使用

    一.使用Lwip协议独立模式开发 最近在STM32F4上边移植了Lwip,Lwip是一个小型开源的TCP/IP协议栈,有无操作系统的支持都可以运行.我当前只测试了TCP Server功能,然后对TCP ...

  4. CISP/CISA 每日一题 14

    CISA 每日一题(答) 自动无人值守运行(LIGHTS-OUT)优势:1.信息系统运行成本的遏制/减少:2.持续运行(24/7):3.减少系统错误和中断次数. I/O 控制人员负责保证:1.批处理信 ...

  5. js进阶 14-8 表单序列化函数serializeArray()和serialize()的区别是什么

    js进阶 14-8 表单序列化函数serializeArray()和serialize()的区别是什么 一.总结 一句话总结:两者都是对表单进行序列化,serializeArray()返回的是json ...

  6. Log4j中为什么设计isDebugEnabled()方法

    转自:https://www.jianshu.com/p/e1eb7ebfb21e 先看下面的代码,在真正执行logger.debug()之前,进行了logger.isDebugEnabled()的判 ...

  7. [D3] Animate Chart Axis Transitions in D3 v4

    When the data being rendered by a chart changes, sometimes it necessitates a change to the scales an ...

  8. 格式化时间的一个好方法(补充moment)

    /** * * 格式化时间 * @param {*} time * @param {*} fmt * @returns * time(new Date(), 'yyyy/MM/dd') ==> ...

  9. sql语句的编程手册 SQL PLUS

    一.SQL PLUS 引言 SQL命令 以下17个是作为语句开头的关键字: alter drop revoke audit grant rollback* commit* insert select ...

  10. Oracle10g中阻塞锁查询更简单

    http://blog.itpub.net/195110/viewspace-677572/ http://blog.sina.com.cn/s/blog_636415010100khcl.html