Mount docker volume to host machine path












5















I need to access test result files in the host from the container. I know that I need to create a volume which maps between host and container, like below, but I get nothing written to the host.



docker run --rm -it -v <host_directory_path>:<container_path> imagename


Dockerfile:



FROM microsoft/dotnet:2.1-sdk AS builder
WORKDIR /app
COPY ./src/MyApplication.Program/MyApplication.Program.csproj ./src/MyApplication.Program/MyApplication.Program.csproj
COPY nuget.config ./
WORKDIR ./src/MyApplication.Program/
RUN dotnet restore
WORKDIR /app
COPY ./src ./src
WORKDIR ./src/MyApplication.Program/
RUN dotnet build MyApplication.Program.csproj -c Release

FROM builder as tester
WORKDIR /app
COPY ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet restore
WORKDIR /app
COPY ./test ./test
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
ENTRYPOINT ["dotnet", "reportgenerator", "-reports:coverage.cobertura.xml", "-targetdir:codecoveragereports", "-reportTypes:htmlInline"]


The command at the entry point is working correctly. It is writing the output to the MyApplication.UnitTests/codecoveragereports directory, but not to the host directory.



My docker run looks as follows:



docker run --rm -it -v /codecoveragereports:/app/test/MyApplication.UnitTests/codecoveragereports routethink.tests:latest


What could I be doing wrong?










share|improve this question























  • Did you try declaring the docker directory as a volume in your dockerfile? VOLUME /app/test/MyApplication.UnitTests/codecoveragereports

    – johnpaton
    Nov 23 '18 at 13:21











  • Declaring a VOLUME in the Dockerfile mostly only causes unexpected side-effects; it has no effect on the docker run -v option.

    – David Maze
    Nov 23 '18 at 13:26











  • docs.docker.com/storage/bind-mounts/… "If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured by the bind mount." Your output is being written, but is being obscured when you bind mount the volume at runtime. Just leaving this here as a diagnosis, not a cure.

    – Proyag
    Nov 23 '18 at 13:28













  • @Siyu I assume / represents the path from which I am running docker run?

    – davenewza
    Nov 23 '18 at 14:01











  • @Siyu that was my problem! Thank you - feel free to create an answer for me to accept

    – davenewza
    Nov 23 '18 at 14:06
















5















I need to access test result files in the host from the container. I know that I need to create a volume which maps between host and container, like below, but I get nothing written to the host.



docker run --rm -it -v <host_directory_path>:<container_path> imagename


Dockerfile:



FROM microsoft/dotnet:2.1-sdk AS builder
WORKDIR /app
COPY ./src/MyApplication.Program/MyApplication.Program.csproj ./src/MyApplication.Program/MyApplication.Program.csproj
COPY nuget.config ./
WORKDIR ./src/MyApplication.Program/
RUN dotnet restore
WORKDIR /app
COPY ./src ./src
WORKDIR ./src/MyApplication.Program/
RUN dotnet build MyApplication.Program.csproj -c Release

FROM builder as tester
WORKDIR /app
COPY ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet restore
WORKDIR /app
COPY ./test ./test
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
ENTRYPOINT ["dotnet", "reportgenerator", "-reports:coverage.cobertura.xml", "-targetdir:codecoveragereports", "-reportTypes:htmlInline"]


The command at the entry point is working correctly. It is writing the output to the MyApplication.UnitTests/codecoveragereports directory, but not to the host directory.



My docker run looks as follows:



docker run --rm -it -v /codecoveragereports:/app/test/MyApplication.UnitTests/codecoveragereports routethink.tests:latest


What could I be doing wrong?










share|improve this question























  • Did you try declaring the docker directory as a volume in your dockerfile? VOLUME /app/test/MyApplication.UnitTests/codecoveragereports

    – johnpaton
    Nov 23 '18 at 13:21











  • Declaring a VOLUME in the Dockerfile mostly only causes unexpected side-effects; it has no effect on the docker run -v option.

    – David Maze
    Nov 23 '18 at 13:26











  • docs.docker.com/storage/bind-mounts/… "If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured by the bind mount." Your output is being written, but is being obscured when you bind mount the volume at runtime. Just leaving this here as a diagnosis, not a cure.

    – Proyag
    Nov 23 '18 at 13:28













  • @Siyu I assume / represents the path from which I am running docker run?

    – davenewza
    Nov 23 '18 at 14:01











  • @Siyu that was my problem! Thank you - feel free to create an answer for me to accept

    – davenewza
    Nov 23 '18 at 14:06














5












5








5








I need to access test result files in the host from the container. I know that I need to create a volume which maps between host and container, like below, but I get nothing written to the host.



docker run --rm -it -v <host_directory_path>:<container_path> imagename


Dockerfile:



FROM microsoft/dotnet:2.1-sdk AS builder
WORKDIR /app
COPY ./src/MyApplication.Program/MyApplication.Program.csproj ./src/MyApplication.Program/MyApplication.Program.csproj
COPY nuget.config ./
WORKDIR ./src/MyApplication.Program/
RUN dotnet restore
WORKDIR /app
COPY ./src ./src
WORKDIR ./src/MyApplication.Program/
RUN dotnet build MyApplication.Program.csproj -c Release

FROM builder as tester
WORKDIR /app
COPY ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet restore
WORKDIR /app
COPY ./test ./test
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
ENTRYPOINT ["dotnet", "reportgenerator", "-reports:coverage.cobertura.xml", "-targetdir:codecoveragereports", "-reportTypes:htmlInline"]


The command at the entry point is working correctly. It is writing the output to the MyApplication.UnitTests/codecoveragereports directory, but not to the host directory.



My docker run looks as follows:



docker run --rm -it -v /codecoveragereports:/app/test/MyApplication.UnitTests/codecoveragereports routethink.tests:latest


What could I be doing wrong?










share|improve this question














I need to access test result files in the host from the container. I know that I need to create a volume which maps between host and container, like below, but I get nothing written to the host.



docker run --rm -it -v <host_directory_path>:<container_path> imagename


Dockerfile:



FROM microsoft/dotnet:2.1-sdk AS builder
WORKDIR /app
COPY ./src/MyApplication.Program/MyApplication.Program.csproj ./src/MyApplication.Program/MyApplication.Program.csproj
COPY nuget.config ./
WORKDIR ./src/MyApplication.Program/
RUN dotnet restore
WORKDIR /app
COPY ./src ./src
WORKDIR ./src/MyApplication.Program/
RUN dotnet build MyApplication.Program.csproj -c Release

FROM builder as tester
WORKDIR /app
COPY ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj ./test/MyApplication.UnitTests/MyApplication.UnitTests.csproj
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet restore
WORKDIR /app
COPY ./test ./test
WORKDIR ./test/MyApplication.UnitTests/
RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
ENTRYPOINT ["dotnet", "reportgenerator", "-reports:coverage.cobertura.xml", "-targetdir:codecoveragereports", "-reportTypes:htmlInline"]


The command at the entry point is working correctly. It is writing the output to the MyApplication.UnitTests/codecoveragereports directory, but not to the host directory.



My docker run looks as follows:



docker run --rm -it -v /codecoveragereports:/app/test/MyApplication.UnitTests/codecoveragereports routethink.tests:latest


What could I be doing wrong?







docker dockerfile






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 12:58









davenewzadavenewza

15.8k32134293




15.8k32134293













  • Did you try declaring the docker directory as a volume in your dockerfile? VOLUME /app/test/MyApplication.UnitTests/codecoveragereports

    – johnpaton
    Nov 23 '18 at 13:21











  • Declaring a VOLUME in the Dockerfile mostly only causes unexpected side-effects; it has no effect on the docker run -v option.

    – David Maze
    Nov 23 '18 at 13:26











  • docs.docker.com/storage/bind-mounts/… "If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured by the bind mount." Your output is being written, but is being obscured when you bind mount the volume at runtime. Just leaving this here as a diagnosis, not a cure.

    – Proyag
    Nov 23 '18 at 13:28













  • @Siyu I assume / represents the path from which I am running docker run?

    – davenewza
    Nov 23 '18 at 14:01











  • @Siyu that was my problem! Thank you - feel free to create an answer for me to accept

    – davenewza
    Nov 23 '18 at 14:06



















  • Did you try declaring the docker directory as a volume in your dockerfile? VOLUME /app/test/MyApplication.UnitTests/codecoveragereports

    – johnpaton
    Nov 23 '18 at 13:21











  • Declaring a VOLUME in the Dockerfile mostly only causes unexpected side-effects; it has no effect on the docker run -v option.

    – David Maze
    Nov 23 '18 at 13:26











  • docs.docker.com/storage/bind-mounts/… "If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured by the bind mount." Your output is being written, but is being obscured when you bind mount the volume at runtime. Just leaving this here as a diagnosis, not a cure.

    – Proyag
    Nov 23 '18 at 13:28













  • @Siyu I assume / represents the path from which I am running docker run?

    – davenewza
    Nov 23 '18 at 14:01











  • @Siyu that was my problem! Thank you - feel free to create an answer for me to accept

    – davenewza
    Nov 23 '18 at 14:06

















Did you try declaring the docker directory as a volume in your dockerfile? VOLUME /app/test/MyApplication.UnitTests/codecoveragereports

– johnpaton
Nov 23 '18 at 13:21





Did you try declaring the docker directory as a volume in your dockerfile? VOLUME /app/test/MyApplication.UnitTests/codecoveragereports

– johnpaton
Nov 23 '18 at 13:21













Declaring a VOLUME in the Dockerfile mostly only causes unexpected side-effects; it has no effect on the docker run -v option.

– David Maze
Nov 23 '18 at 13:26





Declaring a VOLUME in the Dockerfile mostly only causes unexpected side-effects; it has no effect on the docker run -v option.

– David Maze
Nov 23 '18 at 13:26













docs.docker.com/storage/bind-mounts/… "If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured by the bind mount." Your output is being written, but is being obscured when you bind mount the volume at runtime. Just leaving this here as a diagnosis, not a cure.

– Proyag
Nov 23 '18 at 13:28







docs.docker.com/storage/bind-mounts/… "If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured by the bind mount." Your output is being written, but is being obscured when you bind mount the volume at runtime. Just leaving this here as a diagnosis, not a cure.

– Proyag
Nov 23 '18 at 13:28















@Siyu I assume / represents the path from which I am running docker run?

– davenewza
Nov 23 '18 at 14:01





@Siyu I assume / represents the path from which I am running docker run?

– davenewza
Nov 23 '18 at 14:01













@Siyu that was my problem! Thank you - feel free to create an answer for me to accept

– davenewza
Nov 23 '18 at 14:06





@Siyu that was my problem! Thank you - feel free to create an answer for me to accept

– davenewza
Nov 23 '18 at 14:06












1 Answer
1






active

oldest

votes


















1














Looks like a permission issue.



-v /codecoveragereports:/app/***/codecoveragereports is mounting a directory under the root / which is dangerous and you may not have the permission.



It's better to mount locally, like -v $PWD/codecoveragereports:/app/***/codecoveragereports, where $PWD is an environment variable equal to the current working directory.






share|improve this answer



















  • 1





    Thanks - this works - my problem was that I assumed it was defaulting to the execution directory, without $PWD.

    – davenewza
    Nov 23 '18 at 14:16











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447174%2fmount-docker-volume-to-host-machine-path%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Looks like a permission issue.



-v /codecoveragereports:/app/***/codecoveragereports is mounting a directory under the root / which is dangerous and you may not have the permission.



It's better to mount locally, like -v $PWD/codecoveragereports:/app/***/codecoveragereports, where $PWD is an environment variable equal to the current working directory.






share|improve this answer



















  • 1





    Thanks - this works - my problem was that I assumed it was defaulting to the execution directory, without $PWD.

    – davenewza
    Nov 23 '18 at 14:16
















1














Looks like a permission issue.



-v /codecoveragereports:/app/***/codecoveragereports is mounting a directory under the root / which is dangerous and you may not have the permission.



It's better to mount locally, like -v $PWD/codecoveragereports:/app/***/codecoveragereports, where $PWD is an environment variable equal to the current working directory.






share|improve this answer



















  • 1





    Thanks - this works - my problem was that I assumed it was defaulting to the execution directory, without $PWD.

    – davenewza
    Nov 23 '18 at 14:16














1












1








1







Looks like a permission issue.



-v /codecoveragereports:/app/***/codecoveragereports is mounting a directory under the root / which is dangerous and you may not have the permission.



It's better to mount locally, like -v $PWD/codecoveragereports:/app/***/codecoveragereports, where $PWD is an environment variable equal to the current working directory.






share|improve this answer













Looks like a permission issue.



-v /codecoveragereports:/app/***/codecoveragereports is mounting a directory under the root / which is dangerous and you may not have the permission.



It's better to mount locally, like -v $PWD/codecoveragereports:/app/***/codecoveragereports, where $PWD is an environment variable equal to the current working directory.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 14:12









SiyuSiyu

2,6431727




2,6431727








  • 1





    Thanks - this works - my problem was that I assumed it was defaulting to the execution directory, without $PWD.

    – davenewza
    Nov 23 '18 at 14:16














  • 1





    Thanks - this works - my problem was that I assumed it was defaulting to the execution directory, without $PWD.

    – davenewza
    Nov 23 '18 at 14:16








1




1





Thanks - this works - my problem was that I assumed it was defaulting to the execution directory, without $PWD.

– davenewza
Nov 23 '18 at 14:16





Thanks - this works - my problem was that I assumed it was defaulting to the execution directory, without $PWD.

– davenewza
Nov 23 '18 at 14:16


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447174%2fmount-docker-volume-to-host-machine-path%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Fiat S.p.A.