Skip to content

Commit

Permalink
Improve dockerfiles (microsoft#224)
Browse files Browse the repository at this point in the history
* Improve dockerfiles

* Set docker image distro as ubuntu

* Add Alpine based Dockfile

* Remove line breaks

* Add .dockerignore

* Simply .dockerignore

* Fix arch issue for nano server

* Fix nanoserver docker build issue

* Revert nanoserver dockerfile

---------

Co-authored-by: Badrish Chandramouli <[email protected]>
Co-authored-by: Irina Spiridonova <[email protected]>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent 2ad50bc commit a8570ac
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 50 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Directories
**/bin
**/obj
.git
.vs
.vscode

# Files
.gitignore
**/*.md
docker-compose.yml
docker-compose.*.yml
Dockerfile*
36 changes: 26 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG TARGETARCH
WORKDIR /source
WORKDIR /src

# Copy files
COPY . .
WORKDIR /source/main/GarnetServer
# Copy csproj and restore as distinct layers
COPY libs/client/*.csproj libs/client/
COPY libs/cluster/*.csproj libs/cluster/
COPY libs/common/*.csproj libs/common/
COPY libs/host/*.csproj libs/host/
COPY libs/server/*.csproj libs/server/
COPY libs/storage/Tsavorite/cs/src/core/*.csproj libs/storage/Tsavorite/cs/src/core/
COPY libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/*.csproj libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/
COPY main/GarnetServer/*.csproj main/GarnetServer/
COPY metrics/HdrHistogram/*.csproj metrics/HdrHistogram/

RUN dotnet restore -a $TARGETARCH
RUN dotnet build -a $TARGETARCH -c Release
RUN dotnet restore main/GarnetServer/GarnetServer.csproj -a $TARGETARCH

# Copy and publish app and libraries
RUN dotnet publish -a $TARGETARCH -c Release -o /app --self-contained false -f net8.0
# Copy everthing else and publish app
COPY Garnet.snk Garnet.snk
COPY libs/ libs/
COPY main/ main/
COPY metrics/ metrics/
COPY test/testcerts test/testcerts

WORKDIR /src/main/GarnetServer
RUN dotnet publish -a $TARGETARCH -c Release -o /app --no-restore --self-contained false -f net8.0

# Final stage/image
FROM mcr.microsoft.com/dotnet/runtime:8.0
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime
WORKDIR /app
COPY --from=build /app .

# Run container as a non-root user
USER $APP_UID

# For inter-container communication.
EXPOSE 6379

# Run GarnetServer with an index size of 128MB
ENTRYPOINT ["/app/GarnetServer", "-i", "128m", "--port", "6379"]
ENTRYPOINT ["./GarnetServer", "-i", "128m", "--port", "6379"]
40 changes: 40 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
ARG TARGETARCH
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY libs/client/*.csproj libs/client/
COPY libs/cluster/*.csproj libs/cluster/
COPY libs/common/*.csproj libs/common/
COPY libs/host/*.csproj libs/host/
COPY libs/server/*.csproj libs/server/
COPY libs/storage/Tsavorite/cs/src/core/*.csproj libs/storage/Tsavorite/cs/src/core/
COPY libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/*.csproj libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/
COPY main/GarnetServer/*.csproj main/GarnetServer/
COPY metrics/HdrHistogram/*.csproj metrics/HdrHistogram/

RUN dotnet restore main/GarnetServer/GarnetServer.csproj -a $TARGETARCH

# Copy everthing else and publish app
COPY Garnet.snk Garnet.snk
COPY libs/ libs/
COPY main/ main/
COPY metrics/ metrics/
COPY test/testcerts test/testcerts

WORKDIR /src/main/GarnetServer
RUN dotnet publish -a $TARGETARCH -c Release -o /app --no-restore --self-contained false -f net8.0

# Final stage/image
FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine AS runtime
WORKDIR /app
COPY --from=build /app .

# Run container as a non-root user
USER $APP_UID

# For inter-container communication.
EXPOSE 6379

# Run GarnetServer with an index size of 128MB
ENTRYPOINT ["./GarnetServer", "-i", "128m", "--port", "6379"]
42 changes: 28 additions & 14 deletions Dockerfile.cbl-mariner
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-cbl-mariner2.0 AS build
ARG TARGETARCH

WORKDIR /source

# Copy files
COPY . .
WORKDIR /source/main/GarnetServer

RUN dotnet restore -a $TARGETARCH
RUN dotnet build -a $TARGETARCH -c Release

# Copy and publish app and libraries
RUN dotnet publish -a $TARGETARCH -c Release -o /app --self-contained false --no-restore -f net8.0
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY libs/client/*.csproj libs/client/
COPY libs/cluster/*.csproj libs/cluster/
COPY libs/common/*.csproj libs/common/
COPY libs/host/*.csproj libs/host/
COPY libs/server/*.csproj libs/server/
COPY libs/storage/Tsavorite/cs/src/core/*.csproj libs/storage/Tsavorite/cs/src/core/
COPY libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/*.csproj libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/
COPY main/GarnetServer/*.csproj main/GarnetServer/
COPY metrics/HdrHistogram/*.csproj metrics/HdrHistogram/

RUN dotnet restore main/GarnetServer/GarnetServer.csproj -a $TARGETARCH

# Copy everthing else and publish app
COPY Garnet.snk Garnet.snk
COPY libs/ libs/
COPY main/ main/
COPY metrics/ metrics/
COPY test/testcerts test/testcerts

WORKDIR /src/main/GarnetServer
RUN dotnet publish -a $TARGETARCH -c Release -o /app --no-restore --self-contained false -f net8.0

# Final stage/image
FROM mcr.microsoft.com/dotnet/runtime:8.0-cbl-mariner2.0 AS runtime

WORKDIR /app
COPY --from=build /app .

# Run container as a non-root user
USER $APP_UID

# For inter-container communication.
EXPOSE 6379

# Run GarnetServer with an index size of 128MB
ENTRYPOINT ["/app/GarnetServer", "-i", "128m", "--port", "6379"]
ENTRYPOINT ["./GarnetServer", "-i", "128m", "--port", "6379"]
39 changes: 25 additions & 14 deletions Dockerfile.chiseled
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
ARG TARGETARCH

WORKDIR /source

# Copy files
COPY . .
WORKDIR /source/main/GarnetServer

RUN dotnet restore -a $TARGETARCH
RUN dotnet build -a $TARGETARCH -c Release

# Copy and publish app and libraries
RUN dotnet publish -a $TARGETARCH -c Release -o /app --self-contained false --no-restore -f net8.0
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY libs/client/*.csproj libs/client/
COPY libs/cluster/*.csproj libs/cluster/
COPY libs/common/*.csproj libs/common/
COPY libs/host/*.csproj libs/host/
COPY libs/server/*.csproj libs/server/
COPY libs/storage/Tsavorite/cs/src/core/*.csproj libs/storage/Tsavorite/cs/src/core/
COPY libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/*.csproj libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/
COPY main/GarnetServer/*.csproj main/GarnetServer/
COPY metrics/HdrHistogram/*.csproj metrics/HdrHistogram/

RUN dotnet restore main/GarnetServer/GarnetServer.csproj -a $TARGETARCH

# Copy everthing else and publish app
COPY Garnet.snk Garnet.snk
COPY libs/ libs/
COPY main/ main/
COPY metrics/ metrics/
COPY test/testcerts test/testcerts

WORKDIR /src/main/GarnetServer
RUN dotnet publish -a $TARGETARCH -c Release -o /app --no-restore --self-contained false -f net8.0

# Final stage/image
FROM mcr.microsoft.com/dotnet/runtime:8.0-jammy-chiseled AS runtime

WORKDIR /app
COPY --from=build /app .

# For inter-container communication.
EXPOSE 6379

# Run GarnetServer with an index size of 128MB
ENTRYPOINT ["/app/GarnetServer", "-i", "128m", "--port", "6379"]
ENTRYPOINT ["./GarnetServer", "-i", "128m", "--port", "6379"]
2 changes: 1 addition & 1 deletion Dockerfile.nanoserver
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ COPY --from=build /app .
EXPOSE 6379

# Run GarnetServer with an index size of 128MB
ENTRYPOINT ["/app/GarnetServer.exe", "-i", "128m", "--port", "6379"]
ENTRYPOINT ["/app/GarnetServer.exe", "-i", "128m", "--port", "6379"]
37 changes: 26 additions & 11 deletions Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build
ARG TARGETARCH
WORKDIR /src

WORKDIR /source
# Copy csproj and restore as distinct layers
COPY libs/client/*.csproj libs/client/
COPY libs/cluster/*.csproj libs/cluster/
COPY libs/common/*.csproj libs/common/
COPY libs/host/*.csproj libs/host/
COPY libs/server/*.csproj libs/server/
COPY libs/storage/Tsavorite/cs/src/core/*.csproj libs/storage/Tsavorite/cs/src/core/
COPY libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/*.csproj libs/storage/Tsavorite/cs/src/devices/AzureStorageDevice/
COPY main/GarnetServer/*.csproj main/GarnetServer/
COPY metrics/HdrHistogram/*.csproj metrics/HdrHistogram/

# Copy files
COPY . .
WORKDIR /source/main/GarnetServer
RUN dotnet restore main/GarnetServer/GarnetServer.csproj -a $TARGETARCH

RUN dotnet restore -a $TARGETARCH
RUN dotnet build -a $TARGETARCH -c Release
# Copy everthing else and publish app
COPY Garnet.snk Garnet.snk
COPY libs/ libs/
COPY main/ main/
COPY metrics/ metrics/
COPY test/testcerts test/testcerts

# Copy and publish app and libraries
RUN dotnet publish -a $TARGETARCH -c Release -o /app --self-contained false -f net8.0
WORKDIR /src/main/GarnetServer
RUN dotnet publish -a $TARGETARCH -c Release -o /app --no-restore --self-contained false -f net8.0

# Final stage/image
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime
FROM mcr.microsoft.com/dotnet/runtime:8.0-jammy AS runtime
WORKDIR /app
COPY --from=build /app .

# Run container as a non-root user
USER $APP_UID

# For inter-container communication.
EXPOSE 6379

# Run GarnetServer with an index size of 128MB
ENTRYPOINT ["/app/GarnetServer", "-i", "128m", "--port", "6379"]
ENTRYPOINT ["./GarnetServer", "-i", "128m", "--port", "6379"]

0 comments on commit a8570ac

Please sign in to comment.