How to copy folders to docker image from Dockerfile?

后端 未结 10 650
走了就别回头了
走了就别回头了 2021-01-31 01:41

I tried the following command in my Dockerfile: COPY * / and got mighty surprised at the result. Seems the naive docker code traverses the directories from the glob

10条回答
  •  礼貌的吻别
    2021-01-31 02:14

    Use ADD (docs)

    The ADD command can accept as a parameter:

    1. A folder within the build folder (the same folder as your Dockerfile). You would then add a line in your Dockerfile like this:
    ADD folder /path/inside/your/container
    

    or

    1. A single-file archive anywhere in your host filesystem. To create an archive use the command:
    tar -cvzf newArchive.tar.gz /path/to/your/folder
    

    You would then add a line to your Dockerfile like this:

    ADD /path/to/archive/newArchive.tar.gz  /path/inside/your/container
    

    Notes:

    • ADD will automatically extract your archive.
    • presence/absence of trailing slashes is important, see the linked docs

提交回复
热议问题