代码之家  ›  专栏  ›  技术社区  ›  deathangel908

为docker卷创建目录

  •  0
  • deathangel908  · 技术社区  · 7 年前

    我想创建docker卷并将目录和文件添加到其中,而无需创建额外的容器/图像或在最短的时间内。这东西会进入脚本,所以像 -it bash 不会的。

    with :

    docker container create --name dummy -v myvolume:/root hello-world
    docker cp c:\myfolder\myfile.txt dummy:/root/myfile.txt
    docker rm dummy
    

    如何创建空目录?:

    mkdir lol; docker cp ./lol dummy:/root/lol # cannot copy directory

    attempt 2

    docker commit [CONTAINER_ID] temporary_image
    docker run --entrypoint=bash -it temporary_image
    

    这个东西需要用bash拉图像。

    0 回复  |  直到 7 年前
        1
  •  0
  •   Thesane    5 年前

    这对我有用,你可以试试。我正按照剧本做着同样的事情

    VOL_NAME=temp_vol
    docker volume create $VOL_NAME
    docker run -v $VOL_NAME:/root --name helper busybox true
    mkdir tmp
    docker cp tmp helper:/root/dir0
    docker cp tmp helper:/root/dir1
    docker cp tmp helper:/root/dir2
    rm -rf tmp
    docker rm helper
    # check volume
    sudo ls /var/lib/docker/volumes/$VOL_NAME/_data
    dir0 dir1 dir2
    
    推荐文章