[Docker] Create a Volume
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的更多相关文章
- (转)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 ...
- [转帖]Docker的数据管理(volume/bind mount/tmpfs)
Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs) https://www.cnblogs.com/zhuochong/p/10069719.html do ...
- [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 ...
- Docker学习之volume
提供独立于容器之外的持久化存储 容器中的数据会随着容器的消失而消失,为了解决这个问题,产生了数据卷volume. 例子,比如说mysql容器,msyql中的数据应该是持久化的,故应该存储在volume ...
- 解决 Windows Docker 安装 Gitlab Volume 权限问题
本文首发于我的个人博客,解决 Windows Docker 安装 Gitlab Volume 权限问题 ,欢迎访问! 记录一下 Windows10 下 Docker 安装 Gitlab 的步骤. Ca ...
- Docker数据卷Volume实现文件共享、数据迁移备份(三)
数据卷volume功能特性 数据卷 是一个可供一个或多个容器使用的特殊目录,实现让容器中的一个目录和宿主机中的一个文件或者目录进行绑定.数据卷 是被设计用来持久化数据的对于数据卷你可以理解为NFS中的 ...
- Docker(10)- docker create 命令详解
如果你还想从头学起 Docker,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1870863.html 作用 创建一个新的容器但不启动它 ...
- Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs)
Docker提供了三种不同的方式用于将宿主的数据挂载到容器中:volumes,bind mounts,tmpfs volumes.当你不知道该选择哪种方式时,记住,volumes总是正确的选择. vo ...
- [Docker] Create Docker Volumes for Persistent Storage
Docker containers are stateless by default. In order to persist filesystem changes, you must use doc ...
随机推荐
- MSSQL相关用法
一.分页查询 方式一(row_number): SELECT TOP pageSize * FROM (SELECT row_number() OVER (ORDER BY orderColumn) ...
- Python之字符串切片
切片操作(slice)可以从一个字符串中获取子字符串(字符串的一部分).我们使用一对方括号.起始偏移量start.终止偏移量end 以及可选的步长step 来定义一个分片. 格式: [start:en ...
- Redis学习总结和相关资料
因为别人都在用Redis,所以我不得不用Redis. 听起来感觉我很菜的样子,事实上和菜没有关系. 一是由于别人都用,作为后来者,没有"先发"优势,只能顺着别人的思路来做.当前 ...
- 自定义Base 64加密
一.前言 最近做软件需要一个功能,就是对文件进行加密.本来嘛,加密算法一堆一堆的,但是试了几个成熟的加密算法后发现对文件进行加密需要的时间很长,特别是上G的文件,这样客户是接受不了的.最后没办法了,好 ...
- Lightoj 1043 - Triangle Partitioning【二分】
题目链接:http://lightoj.com/volume_showproblem.php? problem=1043 题意:一个三角形ABC,DE//BC.已知三角形ADE和四边形BDEC的面积的 ...
- magento getCarriers 分析
完整的设置订单追踪信息的时候我们可能会用到它.在后台中他在这里设置: 有的时候我们想要设置自己定义的 carrier 比如 顺丰 申通 圆通 ..等等 我们能够先从 magento api 入手分析 ...
- 一个简单http请求的jmeter压测实战流程
1.新建线程组 2.创建http请求 注意:接口路径中的参数值要写变量 3.创建txt文件,存多个参数值 4.创建csv文件,在csv中上传txt文件 5.variable name填写txt中参数值 ...
- Jquery+Ajax+Bootstrap Paginator实现分页的拼接
效果图如下 jsp页面引入bootstrap样式,jquery和bootstrap-paginator.js <link type="text/css" rel=" ...
- C/S与B/S架构比较
一C/S 1.C/S概念 C/S是Client/Server的缩写.服务器通常采用高性能的PC.工作站或小型机,并采用大型数据库系统,如Oracle.Sybase.Informix或 SQL Serv ...
- 洛谷—— P1434 滑雪
https://www.luogu.org/problem/show?pid=1434#sub 题目描述 Michael喜欢滑雪.这并不奇怪,因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜 ...