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学习笔记技巧之给文本加边框

    BorderTextViews.Java package xiaosi.BorderTextView; import android.content.Context; import android.g ...

  2. 基于jQuery的楼层案例

    ~(function() { var flag = true; //点击切换效果 $(".oDR7_asideItem:not(:first)").click(function() ...

  3. Angularjs:实现全选

    html: <div class="input-group"> <span class="input-group-addon" style=& ...

  4. [Javascript AST] 1. Continue: Write a simple Babel plugin

    We want to write a Babel Plugin, which move 'const versionRegex = /(/d+)\.(/d+)\.(/d+)/gi' out of fu ...

  5. [Node.js] Serve Static Files with Express

    In this lesson we will find out how to serve static assets (images, css, stylesheets, etc.) with Exp ...

  6. secureCRT The remote system refused the connection问题解决

    问题: Ubuntu系统必须开启ssh服务后,XP或者其它的主机才干够远程登陆到Ubuntu系统. 1,安装软件包,运行sudo apt-get install openssh-server Ubun ...

  7. WebSocket兼容到低版本浏览器

    就目前而言,WebSocket是最好的Web通信解决方案了.但是IE从10才开始兼容它,对于目前大量IE8存在的市场,原生的WebSocket显然不太实用,我们需要低版本兼容的解决方案.于是我模拟We ...

  8. Solr 写数据流程

    Solr 写数据流程: 1.源字符串首先经过分词器处理,包括:拆分词以及去除stopword. 2.然后经过语言处理,包括大小写转换以及单词转换. 3.将源数据中需要的信息加入到Document中的各 ...

  9. Flask项目之手机端租房网站的实战开发(三)

    说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 接着上一篇博客继续往下写 :https://blog.csdn.net/qq_41782425/article/details/8 ...

  10. tcl -mode

    -exact     严格匹配(如string equal) -glob 通配符式匹配(string match) -regexp   正则表达式匹配(regexp) array get和array ...