0

THE PROBLEM

I'm developping an ai training app. The app uses docker and some folders are shared (mounted). Absolute paths inside and outside docker differ, and I need to create symlinks that work on both.

PATHS

app /opt/shared/app

host: /opt/<client>/app/ai/training/<uuid>/models

docker /workspace/tlt-experiments/training/<uuid>/models

DESCRIPTION

When I execute a training program (inside docker) it will generate in the directory files called model.epoch0.tlt, model.epoch1.tlt, ... model.epoch<n>.tlt

If I cd into host dir or docker dir and execute ln -s model.epoch<n>.tlt model.tlt, I have a link that's valid inside the docker container and in the host machine

But if I execute from the app a command to generate the links, I need to use absolute routing ln -s /opt/<client>/app/ai/training/<uuid>/models/model.epoch<n>.tlt /opt/<client>/app/ai/training/<uuid>/models/model.tlt, which works for the host but is an invalid link pointing to nothing if I execute anything inside the container.

Is there an elegant way to create the link (hopefully not using cd-ln-cd)?

BONUS

The command I currently use to create the link is the following. It helps me get the last epoch (n)

ls -t <host>/models/ | head -1 | xargs -I @ ln -s <host>/models/@ <host>/models/model.tlt

ADITIONAL INFO

This part of the app's code is written in c, but for the links I'm executing unix commands as parsed strings on system(str) calls.

1 Answer 1

0

If I cd into host dir or docker dir and execute ln -s model.epoch<n>.tlt model.tlt, I have a link that's valid inside the docker container and in the host machine

The link target has no relationship to the current directory. Specifying a relative path as the target will always store that exact path in the link, whether you do it after cd-ing somewhere or not.

So you can literally use:

ln -s model.epoch<n>.tlt /opt/<client>/app/ai/training/<uuid>/models/model.tlt

Newer GNU Coreutils versions also add an -r option to automatically transform absolute paths into relative ones.

3
  • Thank you, the -r did the trick!
    – J Pablo F
    Nov 25, 2022 at 18:21
  • You slightly missed the point of my post, I think – you can still do this without -r, though it does make things easier. Nov 26, 2022 at 11:25
  • I didn't miss it, I appreciate the input and your answer did help me to better understand the ln command, yet I needed the trick done and that little additional input on your answer help me do the trick smoothly :D, I was under a lot of pression so my first comment was on what actually solved the problem. Thank you very much!
    – J Pablo F
    Nov 26, 2022 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .