您好,登錄后才能下訂單哦!
今天小編給大家分享一下docker怎么對已經啟動的容器添加目錄映射的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
在自己安裝sharding-proxy時,使用docker run -v
的方式啟動時,只掛載了/opt/shardingsphere-proxy/conf
和/opt/shardingsphere-proxy/ext-lib
這兩個目錄,忘記掛載/opt/shardingsphere-proxy/logs
日志目錄,導致每次查看都得要進入容器內部去查看,很是麻煩,于是考慮如何在不刪除容器重新啟動部署的情況下進行新目錄的映射與掛載
[root@iZ2zedqr9yeos47fg4uor5Z proxy-a]# docker info | grep 'Root' Docker Root Dir: /var/lib/docker [root@iZ2zedqr9yeos47fg4uor5Z proxy-a]#
[root@iZ2zedqr9yeos47fg4uor5Z proxy-a]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6f5f3c195304 apache/shardingsphere-proxy:5.1.1 "/bin/sh -c '${LOCAL…" 4 days ago Up 9 minutes 0.0.0.0:3321->3307/tcp server-proxy-a
[root@iZ2zedqr9yeos47fg4uor5Z proxy-a]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6f5f3c195304 apache/shardingsphere-proxy:5.1.1 "/bin/sh -c '${LOCAL…" 4 days ago Up 11 minutes 0.0.0.0:3321->3307/tcp server-proxy-a [root@iZ2zedqr9yeos47fg4uor5Z proxy-a]# cd /var/lib/docker/containers/ [root@iZ2zedqr9yeos47fg4uor5Z containers]# ll total 64 drwx------ 4 root root 4096 Nov 7 14:20 1d0c21204385f60fa8859b0ff199569988218e449155634470cfb14ff2ceebf9 drwx------ 4 root root 4096 Nov 7 14:20 21a5f8b6e68ee09f8f80381c536b38abec1b8dcb81c69f1c50caeb95e8ebb35f drwx------ 4 root root 4096 Nov 7 14:20 28242c9fd16bd610880d42a773e078221a0d34b1c779935fc0c8609a1b63666a drwx------ 4 root root 4096 Nov 7 14:22 2bc290c8e158229fdc5291a3ea53c5721f5becd39c8cb47cb2f826f6349ac778 drwx------ 4 root root 4096 Nov 7 14:20 2fc0e1b1031abe6b1871332b971ccdc40185b7441e94ba3c266f51d2d4728412 drwx------ 4 root root 4096 Nov 7 14:20 3124c345f129a3c542423c68061c6ded5b41a649b25991125c8e81da7b010e7e drwx------ 4 root root 4096 Nov 7 14:20 4a1e699a3711b92918f711d7ab021a5ac62bab1b8353ed321337c6f94ac50533 drwx------ 4 root root 4096 Nov 7 14:20 4cdc6456250a922e60f3394b26064be0541f04a0c34825c6487e73ed7979705a drwx------ 4 root root 4096 Nov 7 14:20 53d710c37c08b9c2ab0c84fea2059d067bbcbc38f22aa2e654e1c62758b1df44 drwx------ 4 root root 4096 Nov 7 14:41 6f5f3c1953044043672723cdf4f3725c500e77a54e07cd0a4759371c04c0cfa1 drwx------ 4 root root 4096 Nov 7 14:20 73cc941fd394d42b8cbdc8fd7a50fc098b5d56c0323e5b9a786703d21a102d33 drwx------ 4 root root 4096 Nov 7 14:35 8dc6124199b0ef6afbc9d2b542c5a46c8767e7daafd52bfedd53a83491e17db0 drwx------ 4 root root 4096 Nov 7 14:20 9c554d94d5eb6c2c6015994b52ae3f3c31d182dde189d86427840b4a1c5d6477 drwx------ 4 root root 4096 Nov 7 14:20 a073fcd724623a98168564707dccfb9562d94d89c0882ad2fd92798a2137be0d drwx------ 4 root root 4096 Nov 7 14:21 b1191679d1ecea73a74f44ee74b33281fbcccc942307630db02f2cb9e86869d0 drwx------ 4 root root 4096 Nov 7 14:20 eb30519b4804f9ca3c708260e885f99d693332af4a162a956952b601332fed97 [root@iZ2zedqr9yeos47fg4uor5Z containers]# cd 6f5f3c1953044043672723cdf4f3725c500e77a54e07cd0a4759371c04c0cfa1/ [root@iZ2zedqr9yeos47fg4uor5Z 6f5f3c1953044043672723cdf4f3725c500e77a54e07cd0a4759371c04c0cfa1]# ll total 488 -rw-r----- 1 root root 461990 Nov 7 14:41 6f5f3c1953044043672723cdf4f3725c500e77a54e07cd0a4759371c04c0cfa1-json.log drwx------ 2 root root 4096 Nov 2 22:29 checkpoints -rw------- 1 root root 4041 Nov 7 14:41 config.v2.json -rw-r--r-- 1 root root 1705 Nov 7 14:41 hostconfig.json -rw-r--r-- 1 root root 13 Nov 7 14:41 hostname -rw-r--r-- 1 root root 174 Nov 7 14:41 hosts drwx------ 2 root root 4096 Nov 2 22:29 mounts -rw-r--r-- 1 root root 149 Nov 7 14:41 resolv.conf -rw-r--r-- 1 root root 71 Nov 7 14:41 resolv.conf.hash [root@iZ2zedqr9yeos47fg4uor5Z 6f5f3c1953044043672723cdf4f3725c500e77a54e07cd0a4759371c04c0cfa1]#
我們將要修改的文件就是config.v2.json
和hostconfig.json
systemctl stop docker
說明:想要將容器中的/opt/shardingsphere-proxy/logs
目錄映射到宿主機的/atguigu/server/proxy-a/logs
目錄下。
在config.v2.json
文件中找到MountPoints,添加如下/opt/shardingsphere-proxy/logs
的映射即可(這里如果前面還有內容的話,注意逗號)
{ ...... "MountPoints": { ......, "/opt/shardingsphere-proxy/logs": { "Source": "/atguigu/server/proxy-a/logs", "Destination": "/opt/shardingsphere-proxy/logs", "RW": true, "Name": "", "Driver": "", "Type": "bind", "Propagation": "rprivate", "Spec": { "Type": "bind", "Source": "/atguigu/server/proxy-a/logs", "Target": "/opt/shardingsphere-proxy/logs" }, "SkipMountpointCreation": false } }, ...... }
說明:Binds
中添加內容"/atguigu/server/proxy-a/logs:/opt/shardingsphere-proxy/logs"
{ "Binds": [ ......, "/atguigu/server/proxy-a/logs:/opt/shardingsphere-proxy/logs" ], ...... }
systemctl start docker
docker start 容器id
目錄成功映射 出來,查看日志就不用每次很麻煩的進入容器內部查看了
[root@iZ2zedqr9yeos47fg4uor5Z logs]# pwd /atguigu/server/proxy-a/logs [root@iZ2zedqr9yeos47fg4uor5Z logs]# ll total 36 -rw-r--r-- 1 root root 36421 Nov 7 14:41 stdout.log -rw-r--r-- 1 root root 0 Nov 7 14:41 xa_tx1.log -rw-r--r-- 1 root root 0 Nov 7 14:41 xa_tx.lck [root@iZ2zedqr9yeos47fg4uor5Z logs]#
config.v2.json和hostconfig.json文件修改之前,需要關閉docker與容器!如果先修改了這兩個文件,再關閉docker,這兩個文件中的內容會被重置掉,導致新增的目錄映射失效 (自己在這里折騰了很久才發現的!)
config.v2.json和hostconfig.json文件vi命令打開后,并非格式化后的json,這里可以通過:%!python3 -m json.tool命令將其進行格式化,方便查看。
以上就是“docker怎么對已經啟動的容器添加目錄映射”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。