I'm having difficulty getting my mssql-server-windows-express containerized database to retain any created rows after restarting my computer.
It resides in a project that I created with Visual Studio 2017 Community Edition's default "Enable Docker Support" checkbox. I am using Entity Framework Core 2 migrations to create and update the database with ASP.NET Core 2.1.
I feel like the problem might have to do with Docker for Windows having an usual path syntax, but that's just a hunch.
I have tried so many different Stackoverflow and blog suggestions and paths, but the data never persists. I have to ask for help at this point.
Here are two out of the many docker-compose files and ideas I have tried:
version: '3.4'
services:
webpresentation:
image: webpresentation
build:
context: .
dockerfile: WebPresentation\Dockerfile
db:
image: microsoft/mssql-server-windows-express
environment:
ACCEPT_EULA: Y
SA_PASSWORD: Test1
ports:
- "1433:1433"
volumes:
- "C:\\ProgramData\\Docker\\volumes\\dockercompose4363425345347741_sqlvolume:c:\\var/opt/mssql"
volumes:
sqlvolume:
This file compiles, but the rows don't persist after restarting.
version: '3.4'
services:
webpresentation:
image: webpresentation
build:
context: .
dockerfile: WebPresentation\Dockerfile
db:
image: microsoft/mssql-server-windows-express
container_name: myDbSqlExpress
environment:
ACCEPT_EULA: Y
SA_PASSWORD: Test1
'attach_dbs={"dbName":"MyDb","dbFiles":"C:\\ContainerData\\MyDb.mdf","C:\\ContainerData\\MyDb.ldf"}'
ports:
- "1433:1433"
volumes:
- "C:\\DockerData:c:\\ContainerData"
volumes:
sqlvolume:
name: myDb-sqlvolume
This file gives an error:
Error MSB4018 The "GetServiceReferences" task failed unexpectedly. Microsoft.Docker.Utilities.CommandLineClientException: yaml.scanner.ScannerError: while scanning a simple key in "C:\Projects\MyProject\MyApp\docker-compose.yml", line 16, column 7 could not find expected ':'
What am I doing wrong here? Can anyone help me correct either file so the newly created rows persist after restarting the computer?
Thanks very much!