Skip to content

Commit 9d0b531

Browse files
authored
Merge pull request #230 from nanotaboada/feature/dockerfile
feat: add multi-stage Dockerfile for building and running app
2 parents 665cca9 + f290d96 commit 9d0b531

File tree

3 files changed

+390
-1
lines changed

3 files changed

+390
-1
lines changed

.dockerignore

Lines changed: 339 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,339 @@
1+
# https://github.com/dotnet/runtime/blob/main/.dockerignore
2+
3+
### VisualStudio ###
4+
5+
# Tool Runtime Dir
6+
**/.dotnet/
7+
**/.packages/
8+
**/.tools/
9+
10+
# User-specific files
11+
**/*.suo
12+
**/*.user
13+
**/*.userosscache
14+
**/*.sln.docstates
15+
16+
# Build results
17+
**/artifacts/
18+
**/.idea/
19+
**/[Dd]ebug/
20+
**/[Dd]ebugPublic/
21+
**/[Rr]elease/
22+
**/[Rr]eleases/
23+
**/bld/
24+
**/[Bb]in/
25+
**/[Oo]bj/
26+
**/msbuild.log
27+
**/msbuild.err
28+
**/msbuild.wrn
29+
**/msbuild.binlog
30+
**/.deps/
31+
**/.dirstamp
32+
**/.libs/
33+
**/*.lo
34+
**/*.o
35+
36+
# Cross building rootfs
37+
**/cross/rootfs/
38+
**/cross/android-rootfs/
39+
40+
# Visual Studio
41+
**/.vs/
42+
43+
# Ionide
44+
**/.ionide/
45+
46+
# MSTest test Results
47+
**/[Tt]est[Rr]esult*/
48+
**/[Bb]uild[Ll]og.*
49+
50+
#NUNIT
51+
**/*.VisualState.xml
52+
**/TestResult.xml
53+
54+
# Build Results of an ATL Project
55+
**/[Dd]ebugPS/
56+
**/[Rr]eleasePS/
57+
**/dlldata.c
58+
59+
**/*_i.c
60+
**/*_p.c
61+
**/*.ilk
62+
**/*.meta
63+
**/*.obj
64+
**/*.pch
65+
**/*.pdb
66+
!**/_.pdb
67+
**/*.pgc
68+
**/*.pgd
69+
**/*.rsp
70+
**/*.sbr
71+
**/*.tlb
72+
**/*.tli
73+
**/*.tlh
74+
**/*.tmp
75+
**/*.tmp_proj
76+
**/*.log
77+
**/*.vspscc
78+
**/*.vssscc
79+
**/.builds
80+
**/*.pidb
81+
**/*.svclog
82+
**/*.scc
83+
84+
# Chutzpah Test files
85+
**/_Chutzpah*
86+
87+
# Visual C++ cache files
88+
**/ipch/
89+
**/*.aps
90+
**/*.ncb
91+
**/*.opendb
92+
**/*.opensdf
93+
**/*.sdf
94+
**/*.cachefile
95+
**/*.VC.db
96+
97+
# Visual Studio profiler
98+
**/*.psess
99+
**/*.vsp
100+
**/*.vspx
101+
102+
# TFS 2012 Local Workspace
103+
**/$tf/
104+
105+
# Guidance Automation Toolkit
106+
**/*.gpState
107+
108+
# ReSharper is a .NET coding add-in
109+
**/_ReSharper*/
110+
**/*.[Rr]e[Ss]harper
111+
**/*.DotSettings.user
112+
113+
# JustCode is a .NET coding addin-in
114+
**/.JustCode
115+
116+
# TeamCity is a build add-in
117+
**/_TeamCity*
118+
119+
# DotCover is a Code Coverage Tool
120+
**/*.dotCover
121+
122+
# NCrunch
123+
**/_NCrunch_*
124+
**/.*crunch*.local.xml
125+
126+
# MightyMoose
127+
**/*.mm.*
128+
**/AutoTest.Net/
129+
130+
# Web workbench (sass)
131+
**/.sass-cache/
132+
133+
# Installshield output folder
134+
**/[Ee]xpress/
135+
136+
# DocProject is a documentation generator add-in
137+
**/DocProject/buildhelp/
138+
**/DocProject/Help/*.HxT
139+
**/DocProject/Help/*.HxC
140+
**/DocProject/Help/*.hhc
141+
**/DocProject/Help/*.hhk
142+
**/DocProject/Help/*.hhp
143+
**/DocProject/Help/Html2
144+
**/DocProject/Help/html
145+
146+
# Publish Web Output
147+
**/*.[Pp]ublish.xml
148+
**/*.azurePubxml
149+
**/*.pubxml
150+
**/*.publishproj
151+
152+
# NuGet Packages
153+
**/*.nupkg
154+
**/*.nuget.g.props
155+
**/*.nuget.g.targets
156+
**/*.nuget.cache
157+
**/**/packages/*
158+
**/project.lock.json
159+
**/project.assets.json
160+
**/*.nuget.dgspec.json
161+
162+
# Windows Azure Build Output
163+
**/csx/
164+
**/*.build.csdef
165+
166+
# Windows Store app package directory
167+
**/AppPackages/
168+
169+
# Others
170+
**/*.Cache
171+
**/ClientBin/
172+
**/[Ss]tyle[Cc]op.*
173+
**/~$*
174+
**/*.dbmdl
175+
**/*.dbproj.schemaview
176+
**/*.pfx
177+
**/*.publishsettings
178+
**/node_modules/
179+
**/*.metaproj
180+
**/*.metaproj.tmp
181+
**/bin.localpkg/
182+
183+
# RIA/Silverlight projects
184+
**/Generated_Code/
185+
186+
# Backup & report files from converting an old project file
187+
# to a newer Visual Studio version. Backup files are not needed,
188+
# because we have git ;-)
189+
**/_UpgradeReport_Files/
190+
**/Backup*/
191+
**/UpgradeLog*.XML
192+
**/UpgradeLog*.htm
193+
194+
# SQL Server files
195+
**/*.mdf
196+
**/*.ldf
197+
198+
# Business Intelligence projects
199+
**/*.rdl.data
200+
**/*.bim.layout
201+
**/*.bim_*.settings
202+
203+
# Microsoft Fakes
204+
**/FakesAssemblies/
205+
206+
# C/C++ extension for Visual Studio Code
207+
**/browse.VC.db
208+
# Local settings folder for Visual Studio Code
209+
**/**/.vscode/**
210+
!**/**/.vscode/c_cpp_properties.json
211+
212+
### MonoDevelop ###
213+
214+
**/*.pidb
215+
**/*.userprefs
216+
217+
### Windows ###
218+
219+
# Windows image file caches
220+
**/Thumbs.db
221+
**/ehthumbs.db
222+
223+
# Folder config file
224+
**/Desktop.ini
225+
226+
# Recycle Bin used on file shares
227+
**/$RECYCLE.BIN/
228+
229+
# Windows Installer files
230+
**/*.cab
231+
**/*.msi
232+
**/*.msm
233+
**/*.msp
234+
235+
# Windows shortcuts
236+
**/*.lnk
237+
238+
### Linux ###
239+
240+
**/*~
241+
242+
# KDE directory preferences
243+
**/.directory
244+
245+
### OSX ###
246+
247+
**/.DS_Store
248+
**/.AppleDouble
249+
**/.LSOverride
250+
251+
# Icon must end with two \r
252+
**/Icon
253+
254+
# Thumbnails
255+
**/._*
256+
257+
# Files that might appear on external disk
258+
**/.Spotlight-V100
259+
**/.Trashes
260+
261+
# Directories potentially created on remote AFP share
262+
**/.AppleDB
263+
**/.AppleDesktop
264+
**/Network Trash Folder
265+
**/Temporary Items
266+
**/.apdisk
267+
268+
# vim temporary files
269+
**/[._]*.s[a-w][a-z]
270+
**/[._]s[a-w][a-z]
271+
**/*.un~
272+
**/Session.vim
273+
**/.netrwhist
274+
**/*~
275+
276+
# Visual Studio Code
277+
**/.vscode/
278+
279+
# Private test configuration and binaries.
280+
**/config.ps1
281+
**/**/IISApplications
282+
283+
# VS debug support files
284+
**/launchSettings.json
285+
286+
# Snapcraft files
287+
**/.snapcraft
288+
**/*.snap
289+
**/parts/
290+
**/prime/
291+
**/stage/
292+
293+
# CLR prebuilt generated files
294+
!**/src/pal/prebuilt/idl/*_i.c
295+
296+
# Valid 'debug' folder, that contains CLR debugging code
297+
!**/src/**/debug
298+
299+
# Ignore folders created by the CLR test build
300+
**/TestWrappers_x64_[d|D]ebug
301+
**/TestWrappers_x64_[c|C]hecked
302+
**/TestWrappers_x64_[r|R]elease
303+
**/TestWrappers_x86_[d|D]ebug
304+
**/TestWrappers_x86_[c|C]hecked
305+
**/TestWrappers_x86_[r|R]elease
306+
**/TestWrappers_arm_[d|D]ebug
307+
**/TestWrappers_arm_[c|C]hecked
308+
**/TestWrappers_arm_[r|R]elease
309+
**/TestWrappers_arm64_[d|D]ebug
310+
**/TestWrappers_arm64_[c|C]hecked
311+
**/TestWrappers_arm64_[r|R]elease
312+
**/tests/src/common/test_runtime/project.json
313+
314+
**/Vagrantfile
315+
**/.vagrant
316+
317+
# CMake files
318+
**/CMakeFiles/
319+
**/cmake_install.cmake
320+
**/CMakeCache.txt
321+
**/Makefile
322+
323+
# Cross compilation
324+
**/cross/rootfs/*
325+
**/cross/android-rootfs/*
326+
# add x86 as it is ignored in 'Build results'
327+
!**/cross/x86
328+
329+
#python import files
330+
**/*.pyc
331+
332+
# JIT32 files
333+
**/src/jit32
334+
335+
# performance testing sandbox
336+
**/sandbox
337+
338+
# Allow the SQLite database to be included
339+
!src/Dotnet.Samples.AspNetCore.WebApi/Data/players-sqlite3.db

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# - Stage 1 --------------------------------------------------------------------
2+
3+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
4+
WORKDIR /src
5+
6+
# Copy and restore dependencies
7+
COPY src/Dotnet.Samples.AspNetCore.WebApi/*.csproj ./Dotnet.Samples.AspNetCore.WebApi/
8+
RUN dotnet restore ./Dotnet.Samples.AspNetCore.WebApi
9+
10+
# Copy source and publish
11+
COPY src/Dotnet.Samples.AspNetCore.WebApi ./Dotnet.Samples.AspNetCore.WebApi
12+
WORKDIR /src/Dotnet.Samples.AspNetCore.WebApi
13+
RUN dotnet publish -c Release -o /app/publish
14+
15+
# - Stage 2 --------------------------------------------------------------------
16+
17+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
18+
WORKDIR /app
19+
20+
# Copy published output
21+
# Note: This includes the SQLite database because it's marked as <Content> with
22+
# <CopyToOutputDirectory> in the .csproj file. No need to copy it manually.
23+
COPY --from=build /app/publish .
24+
25+
# Add non-root user (aspnetcore) for security hardening
26+
RUN adduser --disabled-password --gecos '' aspnetcore \
27+
&& chown -R aspnetcore:aspnetcore /app
28+
USER aspnetcore
29+
30+
# Set environment variables
31+
ENV ASPNETCORE_URLS=http://+:9000
32+
ENV ASPNETCORE_ENVIRONMENT=Production
33+
34+
# Default entrypoint
35+
ENTRYPOINT ["dotnet", "Dotnet.Samples.AspNetCore.WebApi.dll"]

0 commit comments

Comments
 (0)