Docker - accessing files inside container from host

VISHAL DAGA picture VISHAL DAGA · Oct 17, 2018 · Viewed 14k times · Source

I am new to docker.

I ran a node-10 images and inside the running container I cloned a repository, ran the app which started a server with file watcher. I need to access the codebase inside the container, open it up in an IDE running on the windows host. If that is done, then I also want that as I change the files in the IDE these changes induce the filewatcher in the container.

Any help is appreciated. Thanks,

Answer

Yury Fedorov picture Yury Fedorov · Oct 17, 2018

The concept you are looking for is called volumes. You need to start a container and mount a host directory inside it. For the container, it will be a regular folder, and it will create files in it. For you, it will also be a regular folder. Changes made by either side will be visible to another.

docker run -v /a/local/dir:/a/dir/in/your/container

Note though that you can run into permission issues that you will need to figure out separately.