I have a Dockerfile and I want to add/copy a file.txt from my Desktop. How can I do?
This is my docker file:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim
WORKDIR /app
COPY --from=build-env /app/out ./
# COPY ...
RUN useradd -ms /bin/bash moduleuser
USER moduleuser
ENTRYPOINT ["dotnet", "csharpexamplemodule.dll"]```
CodePudding user response:
Short answer: You don't (see Adding files from outside context). As far as copying (COPY / ADD) goes the file you want to copy to the container needs to be in the same context. Context in this case is the directory of your dockerfile or one of it's subdirectories. Assuming your dockerfile is not on the desktop as well, you are left with 2 options.
- Copy the file from your desktop to the context that docker gets, as mentioned above
- If you don't need the file during the build stage but still within your container, you can use docker mount (docker mount docs).
CodePudding user response:
if you check the docker documentation of the copy command, you should see the following:
https://docs.docker.com/engine/reference/builder/#copy
COPY obeys the following rules:
The <src> path must be inside the context of the build;
you cannot COPY ../something /something, because the first
step of a docker build is to send the context directory
(and subdirectories) to the docker daemon.
So I would suggest you copy the file from your desktop to your docker context (where you run the docker command from). Or to create a symbolic link.
PS: It is a good practice to avoid using ADD if you don't need the tar and remote URL handling.