在Docker容器內(nèi)外互相拷貝數(shù)據(jù)可以通過以下兩種方法實現(xiàn):
docker cp
命令:可以使用docker cp
命令將數(shù)據(jù)從主機復(fù)制到容器內(nèi)或從容器內(nèi)復(fù)制到主機。例如,將本地文件/path/to/file
復(fù)制到容器container_name
的/path/to/destination
目錄中:docker cp /path/to/file container_name:/path/to/destination
或?qū)⑷萜?code>container_name中的文件/path/to/file
復(fù)制到本地主機的/path/to/destination
目錄中:
docker cp container_name:/path/to/file /path/to/destination
my_volume
:docker volume create my_volume
然后將數(shù)據(jù)卷my_volume
掛載到容器container_name
中的/path/to/destination
目錄:
docker run -v my_volume:/path/to/destination container_name
這樣,在主機和容器之間就可以共享數(shù)據(jù)了。