How to access files in host from a Docker Container?

Firstly, etc/hosts is a networking file present on all linux systems, it is not related to drives or docker.

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

for example:

docker run -v /path/on/host:/path/inside/container <image_name>

Leave a Comment