0

According to here (https://docs.docker.com/engine/reference/builder/),

The COPY instruction copies new files or directories from <src> and
adds them to the filesystem of the container at the path <dest>.

I can use COPY command to copy files/directories from the file system of the host/previous stage to the file system of the current container (copy in). But it seems there is no way to copy out (from the file system of the container to the file system of the host).

The only way is to have the built image run as a running container and do another {docker cp container:/xxx/xxx /xxx/xxx} at the host system?

kzfid
  • 688
  • 3
  • 10
  • 17
  • 2
    That's correct; `COPY` is used for building container images. The `docker cp` command is for getting data out of a container. – larsks May 10 '22 at 01:54
  • 1
    It turns out there is a way to do it on current versions of Docker with the BuildKit backend (see the linked question) but if your goal is to have files locally on the host it might be easier to directly build them there without involving Docker. – David Maze May 10 '22 at 10:57
  • Hi @DavidMaze The reason why not build them directly is because there may be dependencies in certain host. I would like to build in an independent environment and regardless of the platform. After the build, I need to copy the built result (the executable/lib) out and to place them somewhere for another people to pick. It seems that the BuildKit provides much more functions than the traditional way. Thanks. ^_^ – kzfid May 13 '22 at 02:29

0 Answers0