问题描述
我在 Ubuntu 服务器主机上有一个 Docker Ubuntu 仿生容器.从容器中,我可以看到主机驱动器安装为/etc/hosts,它不是目录.尝试在不同的位置卸载和重新安装,但抛出 permission denied
错误,当我以 root 身份尝试时会发生这种情况.那么如何访问主机系统的内容?
I have a Docker Ubuntu bionic container on A Ubuntu server host. From the container I can see the host drive is mounted as /etc/hosts which is not a directory. Tried unmounting and remounting on a different location but throws permission denied
error, this happens when I am trying as root.So How do you access the contents of your host system ?
推荐答案
首先,etc/hosts
是一个存在于所有 linux 系统上的网络文件,它与驱动器或 docker 无关.
Firstly, etc/hosts
is a networking file present on all linux systems, it is not related to drives or docker.
其次,如果您想访问 Docker 容器内的部分主机文件系统,您需要使用 volumes.在 docker run 命令中使用 -v
标志,您可以指定主机上的目录以安装到容器中,格式为:
Secondly, if you want to access part of the host filesystem inside a Docker container you need to use volumes. Using the -v
flag in a docker run command you can specify a directory on the host to mount into the container, in the format:
-v /path/on/host:/path/inside/container
例如:
docker run -v /path/on/host:/path/inside/container <image_name>
这篇关于如何从 Docker 容器访问主机中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!