gpt4 book ai didi

docker - 如何在 Dockerfile 中使用 VOLUME 将单个文件保存在目录中?

转载 作者:行者123 更新时间:2023-12-02 21:26:54 26 4
gpt4 key购买 nike

我正在尝试 Dockerize 的这个应用程序在安装目录的根目录中有配置文件。如果我使用 VOLUME要在主机上安装安装目录,我也会在主机上安装应用程序。我只想将配置文件存储在主机上。

我应该在容器中使用硬链接(hard link)并使用 VOLUME 挂载具有硬链接(hard link)的目录吗?硬链接(hard link)甚至可以在容器中工作吗?

最佳答案

您可以挂载单个文件。以下来自 docker 文档 https://docs.docker.com/engine/userguide/containers/dockervolumes/

Mount a host file as a data volume

The -v flag can also be used to mount a single file - instead of just directories - from the host machine.

$ docker run --rm -it -v ~/.bash_history:/root/.bash_history ubuntu /bin/bash

This will drop you into a bash shell in a new container, you will have your bash history from the host and when you exit the container, the host will have the history of the commands typed while in the container.

Note: Many tools used to edit files including vi and sed --in-place may result in an inode change. Since Docker v1.1.0, this will produce an error such as “sed: cannot rename ./sedKdJ9Dy: Device or resource busy”. In the case where you want to edit the mounted file, it is often easiest to instead mount the parent directory.

关于docker - 如何在 Dockerfile 中使用 VOLUME 将单个文件保存在目录中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36359256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com