當docker容器建立後,忘記挂接做本地與容器目錄挂接後,導緻資料存儲都是存在容器中,如果想修改容器内檔案或替換,就需要通過以下指令替換。
docker cp [本地目錄或檔案]: [容器名][容器内目錄]
為了友善,隻要在linux目錄替換,可以通過容器挂載的方式,隻要替換linux的目錄,就能實作容器内的檔案變更。
挂載目錄步驟如下:
1、停止docker運作
systemctl stop docker
2、修改容器的配制檔案
容器路徑:/var/lib/docker/containers/[容器ID]
修改的檔案:
2.1、hostconfig.json
在"Binds"節點中增加挂載目錄的關系,如:
"Binds" ["/opt/docker/test/webapps:/opt/apache-tomcat-8.5.40/webapps"]
前面的是本地目錄,後面的是容器目錄,多個的話,用逗号隔開。
2.2、config.v2.json
在"MountPoints" 節點中增加挂載目錄。如:
"MountPoints": {"/opt/apache-tomcat-8.5.40/webapps": {"Source": "/opt/docker/test/webapps","Destination": "/opt/apache-tomcat-8.5.40/webapps","RW": true,"Name": "","Driver": "","Type": "bind","Propagation": "rprivate","Spec": {"Type": "bind","Source": "/opt/docker/test/webapps","Target": "/opt/apache-tomcat-8.5.40/webapps"},"SkipMountpointCreation": false}}
3、重新docker,開啟容器
systemctl start dockerdocker start [容器名或容器ID]
以上是以修改正在運作的容器的方式挂載目錄。
還有簡單的方式:
送出現有容器為新鏡像,然後重新運作挂載。

碼頭勞工顯示貨物集裝箱