Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions BuildOptimizedImages/src/Web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM microsoft/aspnetcore-build:1.0.1

RUN mkdir /app
WORKDIR /app

ADD project.json .
RUN dotnet restore --no-cache
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a compelling reason to do --no-cache here? You are slowing down the restore for no real gain.

Copy link
Copy Markdown
Author

@friism friism Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because I had misunderstood what the flag does: aspnet/MusicStore#713 (comment)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. That makes sense. Yeah, we probably should talk about clarifying the descriptions and such if it is still the same.


ADD . .
RUN dotnet publish --output /out/. --configuration Release
ADD Dockerfile.deploy /out/Dockerfile
7 changes: 7 additions & 0 deletions BuildOptimizedImages/src/Web/Dockerfile.deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM microsoft/dotnet:1.0.1-core

RUN mkdir /app
WORKDIR /app
ADD . .

CMD dotnet app.dll
3 changes: 1 addition & 2 deletions BuildOptimizedImages/src/Web/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
},

"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
"prepublish": [ "bower install", "dotnet bundle" ]
}
}
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# BuildASPDotNetInAContainer
Sample used to build and test an ASP.NET Core Web app in a container

# Builder container pattern

Here's how to build the app in a container with the full .NET Core SDK, publish, export and then import in a smaller runtime container image:

1. `cd BuildOptimizedImages\src\Web`
2. `$image_id = docker build -q .`
3. `$container_id = docker create $image_id.split(":")[1]`
4. `$tmp_folder_name = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath() + [System.IO.Path]::GetRandomFileName())`
5. `mkdir $tmp_folder_name`
6. ``docker cp $container_id`:/out $tmp_folder_name``
7. `docker rm $container_id`
8. `docker build -t app $tmp_folder_name\out`
9. `Remove-Item -Recurse -Force $tmp_folder_name`
10. `docker run app`