I am using Docker with WSL2 to build a project and would like to access the build results of the container from the host.
It appears there are two ways for accessing the build results:
- Use
docker cp
- Use bind mount
With WSL2 there is a performance decrease when bind mounting the Windows file system (opposed to the WSL2 \\wsl$
Linux file system), see Docker Desktop - Filesharing notification about poor performance and WSL Documentation. However, I would like to avoid using \\wsl$
since I would then have to make sure to pick a unique path there for storing the build results, copying them to the current directory and then properly cleaning the \\wsl$
dir up again (unless I am misunderstand something here?).
This leaves me with the following two options:
- Use
docker cp
This requires three Docker commands:- Build the artifact
docker container run ...
- Copy the artifact to the host
docker cp ...
- Remove container
docker container rm ...
- Build the artifact
- Use bind mount
- Build the artifact in a non-mounted directory (for performance, see above)
- Copy the artifact to the mounted directory
My question is now: Which of these options is more efficient? Or are there any other efficient and simple alternatives?
I would assume docker cp ...
could be more efficient since it might be able to access the container data without the performance penalty a bind mount would have; however the three separate Docker commands deter me a bit since if any of these fails (for whatever reason) I manually have to copy the artifact or clean up the container.