Alexander Mills
Alexander Mills

Reputation: 99990

`cp` vs `rsync` vs something faster

I am using Docker and Docker cannot COPY symlinked files into the image. But the files that are symlinked are not in the 'build context'. So I was going to copy them into the build context with cp, but that's really slow. Is there some way to share the files on two different locations on disk without have to copy them and without using symlinks?

Upvotes: 1

Views: 4556

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

This is not allowed and it won't be

https://github.com/moby/moby/issues/1676

We do not allow this because it's not repeatable. A symlink on your machine is the not the same as my machine and the same Dockerfile would produce two different results. Also having symlinks to /etc/paasswd would cause issues because it would link the host files and not your local files.

If you have common files which are needed in every container then I would put all of them in a shared image and use docker multi build options

FROM mysharedimage as shared

FROM alpine
COPY --from=shared /my/common/stuff /common
....

Again still not the most elegant solution but, because when you do docker build the current context is zipped and sent to the docker daemon, soft links won't work.

You can create hard links but then hard links point to inodes and they don't show you which file they point to. Soft links on other tell you where they point to but the build doesn't sent them.

ln /source/file /dest/file

So your call really what you want to do and how you want to.

Upvotes: 1

Related Questions