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 |