Hello all!

Can you mount any folder a docker image is running in?

So for example, if I have a python script creating a file “./hello.txt”, it would be written in the folder where I launch “docker-compose up” ?

I have figured out how to write the hello.txt to a subfolder like /data/ (by mapping an image-local folder to /data/), but I’d like to use like ./ for the image itself instead. So that the folder I’m launching the docker-compose in on my PC is mapped to ./ in the image, if that makes more sense.

So this works (in the compose.yml):

volumes:

  - ./:/data

but the script must write to “./data/hello.txt”

This doesn’t work:

volumes:

  - ./:./

It pops an error: mount path must be absolute

Any idea if this is even possible?

Cheers and thanks !

  • Admiral Patrick@dubvee.org
    link
    fedilink
    English
    arrow-up
    20
    ·
    edit-2
    8 months ago

    You’re close.

    ...
    volumes:
      - ./:/data
    ...
    working_dir:  /data
    

    That will mount your CWD to /data inside the container and then set the working directory inside to that.

    • Loulou@lemmy.mindoki.comOP
      link
      fedilink
      arrow-up
      2
      ·
      8 months ago

      Thank you !!

      One step closer :-D if I have the python file all ready to go in the directory, it works, but I can’t seem to use my binaries (or the python script) if I compile them in into the image only.

      I have my executables in a “binaries_to_use” folder, is there any way to add them to this local work folder? I tried the thing that worked before:

      COPY binaries_to_use/setup /

      but then

      CMD [“./setup”]

      doesn’t work, I guess it’s no longer a “virtual folder for the image” any more?

      Thanks again, I’m getting less dumb about this :-p