Vroeger waren er problemen bij het deployen van applicaties. Namelijk:

Server=localhost,2018 <—- Let op kommadocker build -t demowebsite .docker run -p 2017:80 --name demowebsitecontainer demowebsitedocker-compose builddocker-compose updocker-stop demowebsitecontainerdocker-rm
docker-rmi
Om het project te bouwen en alle dependencies in 1 mapje te zetten, kan het project gepublished worden. Dit kan met de dotnet publish command. Bijvoorbeeld:
dotnet publish -f "netcoreapp2.0" -r "debian.8-x64" -c debug -o "obj\Docker\publish"Om het publishen en docker-composen makkelijk te maken, heb ik voor de case het onderstaande PowerShell scriptje geschreven. Bij deze case werd de volgende mappenstructuur gehanteerd:
Het benoemde script is ‘PublishAndStart.ps1’ (locatie van het script is belangrijk omdat er gerefereerd wordt naar parents en childs):
# Define paths
$commandPath = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path)
$frontEndPublishPath = $commandPath `
| Join-Path -ChildPath "FrontEnd" `
| Join-Path -ChildPath "publish"
$backEndPublishPath = $commandPath `
| Join-Path -ChildPath "BackEnd" `
| Join-Path -ChildPath "publish"
$frontEndProjectPath = $commandPath `
| Split-Path -Parent `
| Join-Path -ChildPath "FrontEnd" `
| Join-Path -ChildPath "Case1FrontEnd" `
| Join-Path -ChildPath "Cas.FrontEnd.Web"
$backEndProjectPath = $commandPath `
| Split-Path -Parent `
| Join-Path -ChildPath "BackEnd" `
| Join-Path -ChildPath "Case1BackEnd" `
| Join-Path -ChildPath "Cas.Backend.API"
# Publish backend and frontend projects
cd $frontEndProjectPath
dotnet publish -f "netcoreapp2.0" -r "debian.8-x64" -c debug -o $frontEndPublishPath
cd $backEndProjectPath
dotnet publish -f "netcoreapp2.0" -r "debian.8-x64" -c debug -o $backEndPublishPath
# Start docker
cd $commandPath
docker-compose build
docker-compose up
docker-compose.yml:
version: '3'
services:
caswebsite:
image: casfrontendi
container_name: casfrontend
build:
context: .\frontend
dockerfile: Dockerfile
ports:
- 2030:80
environment:
CasBackendBaseUrl: 'http://casbackend'
casbackend:
image: casbackendi
container_name: casbackend
build:
context: .\backend
dockerfile: Dockerfile
ports:
- 2031:80
environment:
CasDb: 'Server=cassqlserver;Database=CursusDb;User Id=sa;Password=Geheim_101'
ascisqlserver:
image: microsoft/mssql-server-linux:2017-latest
container_name: cassqlserver
ports:
- 2032:1433
environment:
ACCEPT_EULA: Y
SA_PASSWORD: Geheim_101
FrontEnd\Dockerfile:
FROM microsoft/aspnetcore
ARG source
WORKDIR /App
COPY ${source:-./publish} .
EXPOSE 80
ENTRYPOINT ["dotnet","Cas.FrontEnd.Web.dll"]
BackEnd\Dockerfile:
FROM microsoft/aspnetcore
ARG source
WORKDIR /app
COPY ${source:-./publish} .
EXPOSE 80
ENTRYPOINT ["dotnet","Cas.BackEnd.API.dll"]