How to build and run a .NET Core Console app in Docker which contains multiple libs?












0















I'm struggling to find a good example of doing this, so hoping for some help.



My project/file structure is like this:



src
srcBulkImporter
srcBulkImporterBulkImporter.csproj
srclib1
srclib1lib1.csproj
srclib2
srclib2lib2.csproj


So, i'm trying to dockerize BulkImporter. To build the app, it needs lib1 and lib2.



I'm trying to do a multi-stage docker build, so a build + runtime image.



Here's my current Dockerfile:



FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

# copy everything and build the project
COPY . ./
RUN dotnet restore src/BulkImporter/*.csproj
RUN dotnet publish src/BulkImporter/*.csproj -c Release -o out

# build runtime image
FROM microsoft/dotnet:2.1-runtime
WORKDIR /app
COPY --from=build-env /app/src/BulkImporter/out ./
ENTRYPOINT ["dotnet", "BulkImporter.dll"]


But, it doesn't seem right. I don't know if i need to 'build everything'. Also, i'm got a csv file in my app, that is erroring when i run the app, as it's looking in an app/Data/mycsv.csv, when normally it exists in /Data/mycsv.csv.



So i think there's some problems with my Dockerfile.



Can someone point me to a good example of how to do this, or tell me what's wrong with my Dockerfile?



Thanks



EDIT



I've updated my Dockerfile to be closely based on the dotnet docker example.



It's building fine, but still facing the CSV issue.



Here's my updated dockerfile:



FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY src/BulkImporter/BulkImporter.csproj ./BulkImporter/
COPY src/Domain/Domain.csproj ./Domain/
COPY src/ElasticSearch.SearchService/ElasticSearch.SearchService.csproj ./ElasticSearch.SearchService/
WORKDIR /app/BulkImporter
RUN dotnet restore

# copy and publish app and libraries
WORKDIR /app/
COPY src/BulkImporter/. ./BulkImporter/
COPY src/Domain/. ./Domain/
COPY src/ElasticSearch.SearchService/. ./ElasticSearch.SearchService/
WORKDIR /app/BulkImporter
RUN dotnet publish -c Release -o out

# build final release runtime image
FROM microsoft/dotnet:2.1-runtime AS runtime
WORKDIR /app
COPY --from=build /app/BulkImporter/out ./
ENTRYPOINT ["dotnet", "BulkImporter.dll"]


I'm building the image from the folder above the src folder, with the following command:




docker build -t bulkimporter . -f .srcBulkImporterDockerfile




The error i get when running is:

Could not find file '/app/FakeDatalocations.csv'.



Yet when i do a dotnet publish from the BulkImporter folder on my PC, the binReleasenetcoreapp2.1publishFakeData folder has the locations.csv file there.



The code that loads the CSV is this:



var suburbLines = (await File.ReadAllLinesAsync("FakeData\locations.csv")).Skip(1);


(runs fine outside Docker).



Can anyone spot the problem?










share|improve this question

























  • Can you add the code that loads the .csv file? How are you getting the directory/path to read the file from?

    – Simply Ged
    Nov 23 '18 at 4:55











  • Can you add the exact errors? Also, "But, it doesn't seem right." doesn't add much information. Can you add more exact details?

    – Omair Majid
    Nov 23 '18 at 14:22











  • @SimplyGed updated

    – RPM1984
    Nov 25 '18 at 22:25











  • @omajid updated. "But it doesnt seem right" was in reference to the fact i needed to 'copy everything', when i shouldn't need to. But, i solved that with the dotnet sample one. So the only problem remaining is reading the CSV.

    – RPM1984
    Nov 25 '18 at 22:25
















0















I'm struggling to find a good example of doing this, so hoping for some help.



My project/file structure is like this:



src
srcBulkImporter
srcBulkImporterBulkImporter.csproj
srclib1
srclib1lib1.csproj
srclib2
srclib2lib2.csproj


So, i'm trying to dockerize BulkImporter. To build the app, it needs lib1 and lib2.



I'm trying to do a multi-stage docker build, so a build + runtime image.



Here's my current Dockerfile:



FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

# copy everything and build the project
COPY . ./
RUN dotnet restore src/BulkImporter/*.csproj
RUN dotnet publish src/BulkImporter/*.csproj -c Release -o out

# build runtime image
FROM microsoft/dotnet:2.1-runtime
WORKDIR /app
COPY --from=build-env /app/src/BulkImporter/out ./
ENTRYPOINT ["dotnet", "BulkImporter.dll"]


But, it doesn't seem right. I don't know if i need to 'build everything'. Also, i'm got a csv file in my app, that is erroring when i run the app, as it's looking in an app/Data/mycsv.csv, when normally it exists in /Data/mycsv.csv.



So i think there's some problems with my Dockerfile.



Can someone point me to a good example of how to do this, or tell me what's wrong with my Dockerfile?



Thanks



EDIT



I've updated my Dockerfile to be closely based on the dotnet docker example.



It's building fine, but still facing the CSV issue.



Here's my updated dockerfile:



FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY src/BulkImporter/BulkImporter.csproj ./BulkImporter/
COPY src/Domain/Domain.csproj ./Domain/
COPY src/ElasticSearch.SearchService/ElasticSearch.SearchService.csproj ./ElasticSearch.SearchService/
WORKDIR /app/BulkImporter
RUN dotnet restore

# copy and publish app and libraries
WORKDIR /app/
COPY src/BulkImporter/. ./BulkImporter/
COPY src/Domain/. ./Domain/
COPY src/ElasticSearch.SearchService/. ./ElasticSearch.SearchService/
WORKDIR /app/BulkImporter
RUN dotnet publish -c Release -o out

# build final release runtime image
FROM microsoft/dotnet:2.1-runtime AS runtime
WORKDIR /app
COPY --from=build /app/BulkImporter/out ./
ENTRYPOINT ["dotnet", "BulkImporter.dll"]


I'm building the image from the folder above the src folder, with the following command:




docker build -t bulkimporter . -f .srcBulkImporterDockerfile




The error i get when running is:

Could not find file '/app/FakeDatalocations.csv'.



Yet when i do a dotnet publish from the BulkImporter folder on my PC, the binReleasenetcoreapp2.1publishFakeData folder has the locations.csv file there.



The code that loads the CSV is this:



var suburbLines = (await File.ReadAllLinesAsync("FakeData\locations.csv")).Skip(1);


(runs fine outside Docker).



Can anyone spot the problem?










share|improve this question

























  • Can you add the code that loads the .csv file? How are you getting the directory/path to read the file from?

    – Simply Ged
    Nov 23 '18 at 4:55











  • Can you add the exact errors? Also, "But, it doesn't seem right." doesn't add much information. Can you add more exact details?

    – Omair Majid
    Nov 23 '18 at 14:22











  • @SimplyGed updated

    – RPM1984
    Nov 25 '18 at 22:25











  • @omajid updated. "But it doesnt seem right" was in reference to the fact i needed to 'copy everything', when i shouldn't need to. But, i solved that with the dotnet sample one. So the only problem remaining is reading the CSV.

    – RPM1984
    Nov 25 '18 at 22:25














0












0








0








I'm struggling to find a good example of doing this, so hoping for some help.



My project/file structure is like this:



src
srcBulkImporter
srcBulkImporterBulkImporter.csproj
srclib1
srclib1lib1.csproj
srclib2
srclib2lib2.csproj


So, i'm trying to dockerize BulkImporter. To build the app, it needs lib1 and lib2.



I'm trying to do a multi-stage docker build, so a build + runtime image.



Here's my current Dockerfile:



FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

# copy everything and build the project
COPY . ./
RUN dotnet restore src/BulkImporter/*.csproj
RUN dotnet publish src/BulkImporter/*.csproj -c Release -o out

# build runtime image
FROM microsoft/dotnet:2.1-runtime
WORKDIR /app
COPY --from=build-env /app/src/BulkImporter/out ./
ENTRYPOINT ["dotnet", "BulkImporter.dll"]


But, it doesn't seem right. I don't know if i need to 'build everything'. Also, i'm got a csv file in my app, that is erroring when i run the app, as it's looking in an app/Data/mycsv.csv, when normally it exists in /Data/mycsv.csv.



So i think there's some problems with my Dockerfile.



Can someone point me to a good example of how to do this, or tell me what's wrong with my Dockerfile?



Thanks



EDIT



I've updated my Dockerfile to be closely based on the dotnet docker example.



It's building fine, but still facing the CSV issue.



Here's my updated dockerfile:



FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY src/BulkImporter/BulkImporter.csproj ./BulkImporter/
COPY src/Domain/Domain.csproj ./Domain/
COPY src/ElasticSearch.SearchService/ElasticSearch.SearchService.csproj ./ElasticSearch.SearchService/
WORKDIR /app/BulkImporter
RUN dotnet restore

# copy and publish app and libraries
WORKDIR /app/
COPY src/BulkImporter/. ./BulkImporter/
COPY src/Domain/. ./Domain/
COPY src/ElasticSearch.SearchService/. ./ElasticSearch.SearchService/
WORKDIR /app/BulkImporter
RUN dotnet publish -c Release -o out

# build final release runtime image
FROM microsoft/dotnet:2.1-runtime AS runtime
WORKDIR /app
COPY --from=build /app/BulkImporter/out ./
ENTRYPOINT ["dotnet", "BulkImporter.dll"]


I'm building the image from the folder above the src folder, with the following command:




docker build -t bulkimporter . -f .srcBulkImporterDockerfile




The error i get when running is:

Could not find file '/app/FakeDatalocations.csv'.



Yet when i do a dotnet publish from the BulkImporter folder on my PC, the binReleasenetcoreapp2.1publishFakeData folder has the locations.csv file there.



The code that loads the CSV is this:



var suburbLines = (await File.ReadAllLinesAsync("FakeData\locations.csv")).Skip(1);


(runs fine outside Docker).



Can anyone spot the problem?










share|improve this question
















I'm struggling to find a good example of doing this, so hoping for some help.



My project/file structure is like this:



src
srcBulkImporter
srcBulkImporterBulkImporter.csproj
srclib1
srclib1lib1.csproj
srclib2
srclib2lib2.csproj


So, i'm trying to dockerize BulkImporter. To build the app, it needs lib1 and lib2.



I'm trying to do a multi-stage docker build, so a build + runtime image.



Here's my current Dockerfile:



FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

# copy everything and build the project
COPY . ./
RUN dotnet restore src/BulkImporter/*.csproj
RUN dotnet publish src/BulkImporter/*.csproj -c Release -o out

# build runtime image
FROM microsoft/dotnet:2.1-runtime
WORKDIR /app
COPY --from=build-env /app/src/BulkImporter/out ./
ENTRYPOINT ["dotnet", "BulkImporter.dll"]


But, it doesn't seem right. I don't know if i need to 'build everything'. Also, i'm got a csv file in my app, that is erroring when i run the app, as it's looking in an app/Data/mycsv.csv, when normally it exists in /Data/mycsv.csv.



So i think there's some problems with my Dockerfile.



Can someone point me to a good example of how to do this, or tell me what's wrong with my Dockerfile?



Thanks



EDIT



I've updated my Dockerfile to be closely based on the dotnet docker example.



It's building fine, but still facing the CSV issue.



Here's my updated dockerfile:



FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY src/BulkImporter/BulkImporter.csproj ./BulkImporter/
COPY src/Domain/Domain.csproj ./Domain/
COPY src/ElasticSearch.SearchService/ElasticSearch.SearchService.csproj ./ElasticSearch.SearchService/
WORKDIR /app/BulkImporter
RUN dotnet restore

# copy and publish app and libraries
WORKDIR /app/
COPY src/BulkImporter/. ./BulkImporter/
COPY src/Domain/. ./Domain/
COPY src/ElasticSearch.SearchService/. ./ElasticSearch.SearchService/
WORKDIR /app/BulkImporter
RUN dotnet publish -c Release -o out

# build final release runtime image
FROM microsoft/dotnet:2.1-runtime AS runtime
WORKDIR /app
COPY --from=build /app/BulkImporter/out ./
ENTRYPOINT ["dotnet", "BulkImporter.dll"]


I'm building the image from the folder above the src folder, with the following command:




docker build -t bulkimporter . -f .srcBulkImporterDockerfile




The error i get when running is:

Could not find file '/app/FakeDatalocations.csv'.



Yet when i do a dotnet publish from the BulkImporter folder on my PC, the binReleasenetcoreapp2.1publishFakeData folder has the locations.csv file there.



The code that loads the CSV is this:



var suburbLines = (await File.ReadAllLinesAsync("FakeData\locations.csv")).Skip(1);


(runs fine outside Docker).



Can anyone spot the problem?







.net docker .net-core dockerfile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 22:24







RPM1984

















asked Nov 23 '18 at 2:51









RPM1984RPM1984

54.9k44200308




54.9k44200308













  • Can you add the code that loads the .csv file? How are you getting the directory/path to read the file from?

    – Simply Ged
    Nov 23 '18 at 4:55











  • Can you add the exact errors? Also, "But, it doesn't seem right." doesn't add much information. Can you add more exact details?

    – Omair Majid
    Nov 23 '18 at 14:22











  • @SimplyGed updated

    – RPM1984
    Nov 25 '18 at 22:25











  • @omajid updated. "But it doesnt seem right" was in reference to the fact i needed to 'copy everything', when i shouldn't need to. But, i solved that with the dotnet sample one. So the only problem remaining is reading the CSV.

    – RPM1984
    Nov 25 '18 at 22:25



















  • Can you add the code that loads the .csv file? How are you getting the directory/path to read the file from?

    – Simply Ged
    Nov 23 '18 at 4:55











  • Can you add the exact errors? Also, "But, it doesn't seem right." doesn't add much information. Can you add more exact details?

    – Omair Majid
    Nov 23 '18 at 14:22











  • @SimplyGed updated

    – RPM1984
    Nov 25 '18 at 22:25











  • @omajid updated. "But it doesnt seem right" was in reference to the fact i needed to 'copy everything', when i shouldn't need to. But, i solved that with the dotnet sample one. So the only problem remaining is reading the CSV.

    – RPM1984
    Nov 25 '18 at 22:25

















Can you add the code that loads the .csv file? How are you getting the directory/path to read the file from?

– Simply Ged
Nov 23 '18 at 4:55





Can you add the code that loads the .csv file? How are you getting the directory/path to read the file from?

– Simply Ged
Nov 23 '18 at 4:55













Can you add the exact errors? Also, "But, it doesn't seem right." doesn't add much information. Can you add more exact details?

– Omair Majid
Nov 23 '18 at 14:22





Can you add the exact errors? Also, "But, it doesn't seem right." doesn't add much information. Can you add more exact details?

– Omair Majid
Nov 23 '18 at 14:22













@SimplyGed updated

– RPM1984
Nov 25 '18 at 22:25





@SimplyGed updated

– RPM1984
Nov 25 '18 at 22:25













@omajid updated. "But it doesnt seem right" was in reference to the fact i needed to 'copy everything', when i shouldn't need to. But, i solved that with the dotnet sample one. So the only problem remaining is reading the CSV.

– RPM1984
Nov 25 '18 at 22:25





@omajid updated. "But it doesnt seem right" was in reference to the fact i needed to 'copy everything', when i shouldn't need to. But, i solved that with the dotnet sample one. So the only problem remaining is reading the CSV.

– RPM1984
Nov 25 '18 at 22:25












0






active

oldest

votes











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%2f53440112%2fhow-to-build-and-run-a-net-core-console-app-in-docker-which-contains-multiple-l%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53440112%2fhow-to-build-and-run-a-net-core-console-app-in-docker-which-contains-multiple-l%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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini