0

I'm trying to mount a directory from the host, on a Docker that I've already created. Everywhere I look, people say to mount a host drive when you run an image. But what are you supposed to do if you've already run the image and have a Docker that already exists? Is this even possible?

One way to solve this is to go ahead and make a 'sequences of Dockers' and make a new one out of the old one. Is this actually a workflow that is considered in line with the way Docker is supposed to work? Or is this just a hack?

Unless you have a crystal ball...and depending on the type of work you might be doing, things could come up tomorrow, next week, etc, and you might need to, say, mount a new drive. I know this is speculation, but it seems to be strange at the very least.

Monica Heddneck
  • 2,973
  • 10
  • 55
  • 89
  • 1
    Possible duplicate of [How can I add a volume to an existing Docker container?](https://stackoverflow.com/questions/28302178/how-can-i-add-a-volume-to-an-existing-docker-container) – Siyu Nov 16 '18 at 23:41
  • I edited the question a bit – Monica Heddneck Nov 16 '18 at 23:47
  • You really want to structure things so it doesn't matter if you delete and recreate the container. If your code is in an image, and your persistent data is in volumes or host directories, then you don't lose anything if your container goes away. – David Maze Nov 17 '18 at 01:17
  • so where do my scripts and code and actual work belong? Inside this Docker or mounted to it? What exactly do you mean by having one's "code in an image"? Isn't an 'image' different than a container? – Monica Heddneck Nov 17 '18 at 01:23

1 Answers1

0

your “Docker” is called container. A container is a running instance of an image. An image is only reflective to a certain stage of your application (code). Moreover, container should be designed to be ephemeral and disposable: they do their job with the code inside and once that code is outdated, you should update the image and recreate new containers. Mounting volumes is not like plug in usb driver to your PC, because again, containers are disposable.

So the hacky solution demonstrates perfectly this concept:

You ‘commit’ the container to create a new image, just a safety mesure in case your container does not strictly follow the design concept. Then create a new container with new volume.

Siyu
  • 11,187
  • 4
  • 43
  • 55