Docker: Can I access to system files?

I am confused to respect the access to system files of the OS where the docker engine is running on. Is this possible? I think that in certain cases I'll need to use certain files to run tests or for reading files for other processes. What should I do in this cases? create an image with the files that I'll need?

Upvotes: 0

Views: 263

Answers (1)

larsks
larsks

Reputation: 312370

To have your container access files on your host where docker is running you would typically use volume mounts. A common idiom is something like this:

docker run -v .:/src myimage /src/run-my-tests

That is, mount my current working directory as /src in the container, then run some sort of shell script that performs tests.

You can use volume mounts to access any files or directories on your host. For example:

docker run -v /:/host ...

Will give you access to the entire host root filesystem. Running:

docker run -v /etc/motd:/etc/motd ...

Would replace /etc/motd in the container with the one on your host. Read the docs for more information.

Upvotes: 2

Related Questions