0

I have created a docker container image, and working inside the container (setting up filesystem, creating code files, installing dependencies etc).

On my Ubuntu machine, I keep a huge file under a directory so called /dataset/my_data/.

When I work in the container, it is not straightforward to access the above directory. Is there any possibility to access it from inside the container image interactively? If yes, how?

yusuf
  • 3,591
  • 8
  • 45
  • 86

1 Answers1

2

You can mount the directory as a volume:

docker ... --mount type=bind,source=/dataset/my_data,target=/some/directory

For example, to run a container called my-container with a bound volume:

docker run -it --mount \
  type=bind,source=/dataset/my_data,target=/target/directory \
  my-container

For all available possibilities, see Docker documentation.

Sami Hult
  • 3,052
  • 1
  • 12
  • 17
  • Thank you for your answer! I am very new and a bit dummy in usage of docker. Let's say my container ID is 12345, and the directory where I want to mount is /root. What would be the comment to do it? I was reading the tutorial you have showed me, even before asking this question. But I couldn't understand anything. That's why I asked this question on stackoverflow. – yusuf Dec 18 '19 at 06:45
  • 1
    Does the more complete example help you? – Sami Hult Dec 18 '19 at 06:50
  • Sami, thanks for your edit. However, the example what you give does not help with binding the folder into the existing container what I already have. I get this error: Unable to find image 'hasan:latest' locally docker: Error response from daemon: pull access denied for hasan, repository does not exist or may require 'docker login'. Given the fact that my container name is 'hasan' – yusuf Dec 18 '19 at 06:56
  • 1
    That is a different problem that has been addressed here: https://stackoverflow.com/questions/56512769/unable-to-find-docker-image-locally – Sami Hult Dec 18 '19 at 07:04
  • I already have the image, do not need to build it. I just have to bind the folder in my already created docker image. I don't want to create a new fresh image for binding. – yusuf Dec 18 '19 at 07:07
  • no, it doesn't. However it shows up when I use docker ps -a. – yusuf Dec 18 '19 at 07:13
  • 1
    In that case I fear you don't have to image locally, as the error message says. This is not related to the original question. – Sami Hult Dec 18 '19 at 07:16