[英]docker volume after upload to github?
如果您只使用代碼刪除了目錄,則該卷可能仍然存在。
使用docker-compose
,您docker-compose.yml
的父目錄的名稱被添加到卷名稱之前。
因此,如果要重用舊卷,則必須確保目錄結構不會更改。
例如,使用以下docker-compose.yml
:
version: "3"
services:
db:
image: postgres
volumes:
- postgres_data:/var/lib/postresql/data
volumes:
postgres_data:
在名為postgres2342
的目錄中導致:
~/workspace/teststuff/postgres2342$ docker-compose up
Creating network "postgres2342_default" with the default driver
Creating volume "postgres2342_postgres_data" with default driver
Pulling db (postgres:)...
latest: Pulling from library/postgres
8ec398bc0356: Pull complete
65a7b8e7c8f7: Pull complete
b7a5676ed96c: Pull complete
3e0ac8617d40: Pull complete
633091ee8d02: Pull complete
b01fa9e356ea: Pull complete
4cd472257298: Pull complete
1716325d7dcd: Pull complete
9b625d69c7c8: Pull complete
74d8b4d9818c: Pull complete
c36f5edbeb97: Pull complete
9b38bb0fb36e: Pull complete
6b5ee1c74b9a: Pull complete
5fcc518252b4: Pull complete
Digest: sha256:52579625addc98a371a644c0399f37e0908b6c28d3b68a0e418394adbe0eb699
Status: Downloaded newer image for postgres:latest
Creating postgres2342_db_1 ... done
Attaching to postgres2342_db_1
請注意Creating volume "postgres2342_postgres_data" with default driver
的開頭和最后一行的Attaching to postgres2342_db_1
Creating volume "postgres2342_postgres_data" with default driver
。 它對應於創建的卷的名稱。
如果我將撰寫文件復制到另一個名為another_postgres
目錄中並生成服務,這將導致:
~/workspace/teststuff/postgres2342$ cd ..
~/workspace/teststuff$ mkdir another_postgres
~/workspace/teststuff$ cp postgres2342/docker-compose.yml another_postgres/
~/workspace/teststuff$ cd another_postgres/
~/workspace/teststuff/another_postgres$ docker-compose up -d
Creating network "another_postgres_default" with the default driver
Creating volume "another_postgres_postgres_data" with default driver
Creating another_postgres_db_1 ... done
如您所見,卷的名稱已更改。
使用docker volume ls
您可以顯示系統上的所有 docker 卷。 所以對包含子字符串postgres
所有卷進行 grep 我得到:
apoehlmann:~/workspace/teststuff/another_postgres$ docker volume ls | grep postgres
local another_postgres_postgres_data
local postgres2342_postgres_data
但是,如果我刪除目錄並重新創建它而不更改其名稱,則一切正常:
~/workspace/teststuff/another_postgres$ cd ..
~/workspace/teststuff$ rm -r postgres2342/
~/workspace/teststuff$ mkdir postgres2342
~/workspace/teststuff$ cp another_postgres/docker-compose.yml postgres2342/
~/workspace/teststuff$ cd postgres2342/
~/workspace/teststuff/postgres2342$ docker-compose up
Starting postgres2342_db_1 ... done
Attaching to postgres2342_db_1
它將 postgres 服務附加到現有卷而不創建新卷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.