Skip to content

Instantly share code, notes, and snippets.

@hartmannr76
Last active July 7, 2018 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hartmannr76/32dfc527f40efc594afe83ceb20030ef to your computer and use it in GitHub Desktop.
Save hartmannr76/32dfc527f40efc594afe83ceb20030ef to your computer and use it in GitHub Desktop.
.NET Docker configuration for multiple containers in a single repo with a dev configuration for debugging

This assumes the following structure:

Dockerfile
docker-compose.yml
src/
    - Api/
        - Api.csproj
    - Daemon/
        - Daemon.csproj
version: '3.4'
services:
web:
build:
context: .
target: dev
args:
APP_SOURCE: Api
environment:
- SOME=var
ports:
- '8000:80'
volumes:
- ./src:/app/code
daemon:
build:
context: .
target: dev
args:
APP_SOURCE: Daemon
links:
- web
environment:
- SOME=var
volumes:
- ./src:/app/code
FROM microsoft/dotnet:2.1.300-sdk as base
ARG APP_SOURCE
WORKDIR /app/code
COPY Directory.Build.props /app
COPY ./src/ /app/code/
RUN dotnet restore ./${APP_SOURCE}/${APP_SOURCE}.csproj
FROM base as dev
# Dev image defaults to recompiling and
# includes debug binaries to remotely attach
RUN apt-get update && \
apt-get install -y unzip && \
curl -sSL https://aka.ms/getvsdbgsh -o '/root/getvsdbg.sh' && \
bash /root/getvsdbg.sh -v latest -l /vsdbg
WORKDIR /app/code
COPY --from=base /app/code .
CMD dotnet watch --project ./${APP_SOURCE}/${APP_SOURCE}.csproj run
FROM base as publisher
ARG APP_SOURCE
WORKDIR /app/code
COPY --from=base /app/code/ .
RUN dotnet publish \
-c Release \
--no-restore \
-o out ./${APP_SOURCE}/${APP_SOURCE}.csproj
FROM microsoft/dotnet:2.1-aspnetcore-runtime as release
ARG APP_SOURCE
WORKDIR /app/code
COPY --from=publisher /app/code/${APP_SOURCE}/out .
ENTRYPOINT dotnet ${APP_SOURCE}.dll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment