docker 修改服务器,docker-修改容器挂载目录的3种方法小结
本文關(guān)鍵詳細(xì)介紹了docker-修改容器初始化目錄的3種方式總結(jié),具備非常好的實(shí)用價(jià)值,期待對(duì)大伙兒有一定的協(xié)助。一起追隨我回來瞧瞧吧
方法一:修改配置文件(需停止docker服務(wù))
1、停止docker服務(wù)
systemctl stop docker.service(重要,修改以前務(wù)必停止docker服務(wù))
2、vim /var/lib/docker/containers/container-ID/config.v2.json
修改配置文件中的目錄部位,隨后儲(chǔ)存撤出
"MountPoints":{"/home":{"Source":"/docker","Destination":"/home","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"//docker/","Target":"/home"}}}
3、起動(dòng)docker服務(wù)
systemctl start docker.service
4、起動(dòng)docker容器
docker start
方法二:遞交目前容器為新鏡像系統(tǒng),隨后再次運(yùn)作它
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5a3422adeead ubuntu:14.04 "/bin/bash" About a minute ago Exited (0) About a minute ago agitated_newton
$ docker commit 5a3422adeead newimagename
$ docker run -ti -v "$PWD/dir1":/dir1 -v "$PWD/dir2":/dir2 newimagename /bin/bash
隨后停止舊容器,并應(yīng)用這一新容器,假如因?yàn)榉N種原因必須新容器應(yīng)用舊名字,請(qǐng)?jiān)趧h掉舊容器后應(yīng)用docker rename。
方法三:export容器為鏡像系統(tǒng),隨后import為新鏡像系統(tǒng)
$docker container export -o ./myimage.docker 容器ID
$docker import ./myimage.docker newimagename
$docker run -ti -v "$PWD/dir1":/dir1 -v "$PWD/dir2":/dir2 newimagename /bin/bash
隨后停止舊容器,并應(yīng)用這一新容器,假如因?yàn)榉N種原因必須新容器應(yīng)用舊名字,請(qǐng)?jiān)趧h掉舊容器后應(yīng)用docker rename。
填補(bǔ)專業(yè)知識(shí):Docker如何重啟后數(shù)據(jù)信息不遺失,教你初始化數(shù)據(jù)信息卷Volume
大伙兒在應(yīng)用Docker布署web應(yīng)用或是mysql數(shù)據(jù)庫查詢時(shí),會(huì)發(fā)覺當(dāng)容器重新啟動(dòng)后,容器運(yùn)作全過程中造成的日志或是數(shù)據(jù)庫查詢數(shù)據(jù)信息都是會(huì)被清除,那麼大家如何保存這種數(shù)據(jù)信息呢?
這就必須掌握docker怎樣初始化宿主機(jī)硬盤目錄,用于永久性儲(chǔ)存數(shù)據(jù)信息。
1. 建立容器時(shí)實(shí)行Docker Volume
應(yīng)用 docker run 指令,能夠運(yùn)作一個(gè) Docker容器,應(yīng)用鏡像系統(tǒng)ubuntu/nginx,初始化當(dāng)?shù)啬夸?tmp/source到容器目錄/tmp/destination
docker run -itd --volume /tmp/source:/tmp/destination --name test ubuntu/nginx bash
根據(jù)ubuntu/nginx鏡像系統(tǒng)建立了一個(gè)Docker容器。
特定容器的名字為test,由 ––name 選擇項(xiàng)特定。
Docker Volume 由 ––volume (能夠縮寫為-v)選擇項(xiàng)特定,服務(wù)器的 /tmp/source 目錄與容器中的 /tmp/destination 目錄一一對(duì)應(yīng)。
2. 查詢Docker Volume
應(yīng)用 docker inspect 指令,能夠查詢 Docker容器 的詳細(xì)資料:
docker inspect --format='{{json .Mounts}}'test | python -m json.tool[{“Destination”: “/tmp/destination”,“Mode”: “”,“Propagation”: “”,“RW”: true,“Source”: “/tmp/source”,“Type”: “bind”}]
應(yīng)用 ––format 選擇項(xiàng),能夠可選擇性查詢必須的容器信息內(nèi)容。 .Mount 為容器的 Docker Volume 信息內(nèi)容。
python -m json.tool 能夠?qū)⑤敵龅膉son字符串?dāng)?shù)組恢復(fù)出廠設(shè)置顯示信息。
Source 表明服務(wù)器上的目錄,即 /tmp/source 。
Destination 為容器中的目錄,即 /tmp/destination。
3. 該設(shè)備文檔能夠同歩到容器
在該設(shè)備/tmp/source目錄中新創(chuàng)建hello.txt文件
touch /tmp/source/hello.txtls /tmp/source/hello.txt
hello.txt文件在容器/tmp/destination/目錄中由此可見
應(yīng)用 docker exec 指令,能夠在容器中運(yùn)行命令。
docker exectest ls /tmp/destination/hello.txt
因此 在宿主機(jī)對(duì)目錄 /tmp/source/ 的修改,能夠同歩到容器目錄 /tmp/destination/ 中。
4. 容器文檔能夠同歩到宿主機(jī)
在容器/tmp/destination目錄中新創(chuàng)建world.txt文件
docker exec test touch /tmp/destination/world.txtdocker exec test ls /tmp/destination/hello.txtworld.txt
world.txt文件在宿主機(jī)/tmp/source/目錄中由此可見
ls /tmp/source/hello.txt world.txt
之上這篇docker-修改容器初始化目錄的3種方式總結(jié)便是我共享給大伙兒的所有內(nèi)容了,期待能給大伙兒一個(gè)參照,也期待大伙兒多多的適用大家。
熱搜詞
總結(jié)
以上是生活随笔為你收集整理的docker 修改服务器,docker-修改容器挂载目录的3种方法小结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql数据库维护_维护MySQL数据
- 下一篇: 福建莆田农村地籍测量项目技术方案