[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 ...
随机推荐
- BZOJ4196: [Noi2015]软件包管理器(树链剖分)
Description Linux用户和OSX用户一定对软件包管理器不会陌生.通过软件包管理器,你可以通过一行命令安装某一个软件包,然后软件包管理器会帮助你从软件源下载软件包,同时自动解决所有的依赖( ...
- codevs 5960 信使
codevs 5960 信使 题目描述 Description 战争时期,前线有n个哨所,每个哨所可能会与其他若干个哨所之间有通信联系.信使负责在哨所之间传递信息,当然,这是要花费一定时间的(以天为单 ...
- 洛谷——P3819 松江1843路
https://www.luogu.org/problem/show?pid=3819 题目描述 涞坊路是一条长L米的道路,道路上的坐标范围从0到L,路上有N座房子,第i座房子建在坐标为x[i]的地方 ...
- EventWaitHandle
在查资料的过程中,我突然想到一个类:EventWaitHandle,也就是本文的主角. 这个类通过在线程之间设置信号量,可以非常方便的控制线程运行的顺序.具体代码如下: 首先全局申明: EventWa ...
- 【例 7-12 UVA - 1343】The Rotation Game
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 迭代加深搜索. 每次抽动操作最多只会让中间那一块的区域离目标的"距离"减少1. 以这个作为剪枝. 枚举最大深度. ...
- hadoop 2.4.1 集群安装二
1:创建文件夹 [jifeng@feng01 hadoop]$ mkdir tmp [jifeng@feng01 hadoop]$ mkdir name [jifeng@feng01 hadoop]$ ...
- nginx源代码分析--事件模块 & 琐碎
通过HUP信息使得NGINX实现又一次读取配置文件,使用USR2信号使得NGINX实现平滑升级. 在nginx中有模块这么一说,对外全部的模块都是ngx_module_t类型,这个结构体作为全部模块的 ...
- Codeforces #28 C.Bath Queue (概率dp)
Codeforces Beta Round #28 (Codeforces format) 题目链接: http://codeforces.com/contest/28/problem/C 题意: 有 ...
- Altium Designer如何设置pcb尺寸
- loadrunner--log的使用总结
1.log的设置方式.在 runtime setting中可以设置log的生成方式:默认的log方式:Enable logging选中,log option是Send messages only wh ...