Docker - cannot mount volume over existing file, file exists

后端 未结 3 1088
感动是毒
感动是毒 2021-02-07 08:30

I\'m trying to build a data container for my application in Docker. I run this command to expose some volumes:

docker run --name svenv.nl-data -v /etc/environmen         


        
相关标签:
3条回答
  • 2021-02-07 09:08

    I guess because you are not mounting a file but instead declaring a mount. Try this notation instead: -v <full path to a file you want to overwrite the target with>:/etc/environment

    0 讨论(0)
  • 2021-02-07 09:10

    Suppose you are under Linux, run the following code

    docker run -it --rm -v /local_dir:/image_root_dir/mount_dir image_name
    

    Here is some detail:

    -it: interactive terminal 
    --rm: remove container after exit the container
    -v: volume or say mount your local directory to a volume
    

    Since the mount function will 'cover' the directory in your image, your should always make a new directory under your images root directory.

    Visit official documentation Use bind mounts to get more information.

    0 讨论(0)
  • 2021-02-07 09:14

    You should use:

    -v /etc/environment:/etc/environment
    

    instead of:

    -v /etc/environment
    

    The former maps container volume to the host volume. The latter tries to create a new volume at /etc/environment and fails since this directory already exists.

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