Docker mount to folder overriding content

后端 未结 1 1099
粉色の甜心
粉色の甜心 2020-12-14 09:10

I have a .net Core web Api having configurations files under a folder called Config. I created the image and a container from it, and I correctly see using the terminal, tha

相关标签:
1条回答
  • 2020-12-14 10:08

    First of all, docker volumes or bind mounts behave like linux mounts.

    If the host volume/mount exists and contains files it will "override" whatever is in the container. If not the container files will be mirrored onto the host volume/mount and the container folder and the host will be in sync. In both cases editing the files on the host will ALWAYS be reflected inside the container.

    In your case, you can do the following:

    docker volume create --driver local \
        --opt type=none \
        --opt device=$configVolumePath \
        --opt o=bind \
        config_vol
    

    This will create a volume which will be persisted in $configVolumePath on the host.

    When creating the container use that volume:

    docker create --volume config_vol:/app/Config
    

    What you will get is on startup, the host folder will be empty and the files from the image will be "copied" onto the host folder. Editing files in $configVolumePath will be reflected inside the container and similarly files edited inside the container /app/Config will be reflected in $configVolumePath on the host.

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