Docker COPY Host ${HOME}/.cache to container

后端 未结 2 994
Happy的楠姐
Happy的楠姐 2021-01-18 11:01

I would like to copy my winetricks cache over to the docker container:

HOST:

~/.cache/winetricks

to CONTAINER

/home         


        
相关标签:
2条回答
  • 2021-01-18 11:49

    https://docs.docker.com/storage/volumes/#choose-the--v-or-mount-flag

    @Charles Duffy is right.

    dockerfile below

    VOLUME ["(change-to-full-path)/.cache/winetrick"]
    

    lanch value below

    -v (change-to-full-path)/.cache/winetricks:/home/myUser/.cache/winetricks
    

    This will allow you to set a volume, and then path it into the container

    0 讨论(0)
  • 2021-01-18 12:04

    So here is my question: Why do I have to make a duplicate of my ~/.cache directory? Why can I not copy a directory from outside of the docker root to the container?

    The first step of a docker build command is to send the build context to the docker engine performing the build. This engine may be on a remote server. This build context is typically a . at the end of the command line indicating to send the current directory as your context.

    This context is used for every COPY and ADD command, and any file not included in the context is unavailable for the COPY and ADD. Changing the behavior to allow all files on the host to be accessible would break the client/server design of docker builds and introduce a security vulnerability where someone could send a malicious Dockerfile to the build server and use that to extract secret data from the server into the image.

    You can change the build context to be your home directory, instead of your project sub-directory. To do this, you'd also need to update all the COPY and ADD commands with the path relative to $HOME. You would also see a significantly longer build time as your entire home directory gets sent to the server.

    For your specific issue, there's a new feature that just entered into experimental called BuildKit. One of the first features being implemented is mounting a directory during a RUN command for the purposes of a packaging cache you only want to pull once.

    0 讨论(0)
提交回复
热议问题