I want to copy folder D:\test
from my host OS (Windows) to my docker image.
My Docker file is D:\Programs>
Docker file
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN mkdir root
RUN cd root
WORKDIR /root
RUN mkdir test
COPY D:/test to /root/test
#USING 'COPY' here instead of 'ADD' because of https://stackoverflow.com/questions/24958140/what-is-the-difference-between-the-copy-and-add-commands-in-a-dockerfile
From folder D:\Programs> I run command docker build . -t test
But I get error:
COPY failed: file not found in build context or excluded by .dockerignore: stat test: file does not exist
I tried commands COPY D:/test to /root/test
and COPY ./test to /root/test
I know this error occurs because the path I copy from has to be relative from the build context (the . in docker build .). It cannot be an arbitrary path on the system outside of the build context.
I thought by using .
I'd be in context D:\
from my build context D:\Programs>
, but I guess not. What should my COPY command look like?
I checked here already:
- https://forums.docker.com/t/copy-files-from-windows-host-to-ubuntu-container/28757
- Dockerfile COPY from a Windows file system to a docker container
- Dockerfile: Copy directory from Windows host to docker container
UPDATE 1
I placed the test
folder in D:\Programs
where my Dockerfile also resides, so I now have structure:
D:\Programs
\Test
Dockerfile
I then ran the build command again where I tried COPY test to /root/test
and COPY ./test to /root/test
, but both fail with the same aforementioned error.