Search code examples
dockerdocker-machinedocker-swarmdocker-swarm-mode

how to sync mac local directory with native docker container?


i am using native docker for mac and i have a small application running with docker container .

currently i am manually copying the data from my mac to docker container using docker cp command.

i want to make it dynamic, i want to put the data in my local directory which should get sync with docker container .

example:

mac local dir : users/vishnu/data/

which should get sync to

`<Docker-container-ID>:/opt/deploy/`

the container is already running ,i should not release the running container . i can only stop and start . is there a way ?? Thanks in advance


Solution

  • host mounted volume.

    when you docker run you add a -v /Users/vishnu/data:/opt/deploy parameters.

    if you need to add a mounted volume to your existing container, use the Kitematic UI. it's easier that way. but in general, you should add this when you docker run.

    ...

    also, FYI - the idea that you can't delete a container is an anti-pattern with Docker. if you can't delete your container, because it would cause too many problems, you're doing something wrong. https://derickbailey.com/2017/04/05/what-i-learned-by-deleting-all-of-my-docker-images-and-containers/