skip to Main Content

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


  1. How do copy application files to docker container when starting

    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 the CopyBinFrom environment variable value.

    docker run -it -e CopyBinFrom=c:pathToBinaries -v c:pathToBinaries:/app myimage
    

    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 the c:pathToBinaries folder. The output of this command should show the c:pathToBinaries folder.

    You can do it this way:

    docker run -it --security-opt label=disable userns=true myimage ls -la /c
    

    P.s.

    Let me know if it works for you, please.

    Login or Signup to reply.
  2. 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 like this (almost already yours).

    FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
    WORKDIR /app
    EXPOSE 8080
    
    FROM base AS app_base
    COPY executable.exe ./ 
    
    # not sure if that is correct
    ENTRYPOINT ["executable.exe"]
    

    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 .

    Pros:

    • Scaling is no problem
    • Sharing images is no problem
    • Better isolation between containers
    • Easy to understand

    Reminder: are not virtual machines. They should not be used like this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search