Home > Blockchain >  Docker mount files to my local system while running the container
Docker mount files to my local system while running the container

Time:10-24

I am using an image academind/node-example-1 which is a simple node image. You can check it https://hub.docker.com/r/academind/node-example-1 here. What I want while I run the image I want to get the same folder & file structure that is there in the Image. I know that can be done via volume. When I use like

docker run -d --rm --name node-test -p 5000:80 academind/node-example-1

Everything is proper But I want to get the codebase while running, so I tried like

docker run -d --rm --name node-test -p 5000:80 -v /Users/souravbanerjee/Documents/node-docker:node-example-1 academind/node-example-1 

Here node-docker is my local folder where I expect the code to be. It runs but not getting the files in the local machine, I'm in doubt here where the source_path:destination_path. Please correct me to please tell me where I'm wrong, or what to do, or my entire thinking is going in the wrong direction or not.

Thanks.

CodePudding user response:

If you read the official doc, you'll see that the first part of the : should be the path somewhere in the host machine (which you're doing), while the later part should match the path "inside" the container (instead you're using image name). Assuming /app being the path (I've taken that course by myself and this is the path AFAIR), it should be:

docker run -d --rm --name node-test -p 5000:80 -v /Users/souravbanerjee/Documents/node-docker:/app academind/node-example-1

CodePudding user response:

I think the correct syntax is to enter the drive information in the volume mapping.

Eg. Users/xxxx/:some/drive/location

However, that would map your empty drive at xxxx over the top of 'location' folder. Thus deleting the existing files in the container.

If you are interested in seeing the contents of the files in the container, you should consider using 'Docker CP' command.

People often use volume mounts to push data (i.e. persistent database files) into a container.

Alternatively, writing log files to the volume mounted location inside the application container. Then those files are then reflected on your local drive

CodePudding user response:

You can copy the files to the current host directory using the command

docker cp node-test:/app .

when the container is running

  • Related