Dockerfile with copy command and relative path

15,568

Reference: Allow Dockerfile from outside build-context

You can try this way

$ cd project-console
$ docker build -f ../project-test/Dockerfile .

Update:

By using docker-compose

build:
  context: ../
  dockerfile: project-test/Dockerfile

../ will be set as the context, it should include project-console and project-test in your case. So that you can COPY project-console/*.csproj in Dockerfile.

Share:
15,568
TitaoYamamoto
Author by

TitaoYamamoto

Updated on June 19, 2022

Comments

  • TitaoYamamoto
    TitaoYamamoto almost 2 years

    Have same way to use copy command with relative path in dockerfile? Im trying to use:

    COPY ./../folder/*.csproj ./
    

    OBS.: My struct folder (Im running the dockerfile on project-test and another files is in project-console folder) is:

    |- project-console

    |- project-test

    And Im receive the follow error:

    ERROR: service 'app' failed to build: COPY failed: no source files were specified.

    My purpose is have two projects in the same docker. I have a dotnet core console and another with unity test (NUnity), Im trying run the unity test in docker.

    UPDATE

    Is possible to use Multi-stage: https://docs.docker.com/develop/develop-images/multistage-build/

    Or using docker-compose with build: https://docs.docker.com/engine/reference/commandline/build/

    Like:

    services: 
    
    worker:
        build:
          context: ./workers
          dockerfile: Dockerfile
    
  • TitaoYamamoto
    TitaoYamamoto over 5 years
    Hi @Kuanlin Chen, Im using docker-compose and I need to do this inside the Dockerfile. Do you know another way to do that?
  • Corey
    Corey over 5 years
    Hi @TitaoYamamoto I have updated my answer, please have a try.