简体   繁体   中英

How can I mount a local directory to an existing docker container?

I want to mount a local directory from a private cloud to an container there using -v flag. When I run docker run -it -v "$(pwd)":/name-of-the-folder-inside-container existing-container bash , the directory gets mounted. However, I go to the container running this command docker run -it existing-container bash , I don't see the directory that mounted earlier. It is the same container that I am trying to access using the second command but the filesystem doesn't show me the folder in which I mounted the local directory.

docker run -it -v "$(pwd)":/name-of-the-folder-inside-container existing-container bash

When you run docker run -it existing-container bash you're not actually connecting to the old container with the same name, but generating a new container from the same image .

Docker run is used to spin up a new container. Docker start will start an existing, but currently stopped container. Docker exec is used to run a command on an existing container.

Try to use docker exec -it existing-container bash when accessing the container again after initially creating it with the mounted volume instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM