I have a container that
- contains all runtimes needed for my app to run.
- does not contain the application
The idea is, that I don’t need to rebuild the image in order to deploy new version of my app.
How do I copy files (my application binaries) from host to container when starting the container?
My Attempt
when I run docker run -it -e CopyBinFrom=c:pathToBinaries
myimage
the folder c:pathToBinaries is not copied into the container
dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
ENV CopyBinFrom=.
WORKDIR /app
EXPOSE 8080
FROM base AS app_base
# ignores value from docker run
COPY $CopyBinFrom ./
ENTRYPOINT ["cmd"]
2
Answers
Your dockerfile looks good.
Try to troubleshoot the issue this way:
1/ You can check whether the
CopyBinFrom
environment variable was being passed to the container correctly or not. This command’s output will show theCopyBinFrom
environment variable value.2/ Also you should be sure that the
c:pathToBinaries
folder exists on the host machine. Otherwise, create it.3/ Furthermore you should be sure that the
myimage
image has the necessary permissions to access thec:pathToBinaries folder
. The output of this command should show thec:pathToBinaries
folder.You can do it this way:
P.s.
Let me know if it works for you, please.
With layer caching you have not to "rebuilt overhead". There is no need for mounting files somehow.
If you want to use your executable(s) directly then just use a dockerfile like this (almost already yours).
With that you can just run
docker build . -t yourApp:yourTag
.When you run this command twice, then you will see that the second run will be much faster. For that you have to use a docker-tag.
Pros:
Reminder: docker-container are not virtual machines. They should not be used like this.