Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

EF Core in Containerized ASP.NET Core APIs

231 views

Published on

Slides (with resources) from 2019 conferences (BASTA! & Concatenate)
twitter.com/julielerman
thedatafarm.com
about.me/julielerman

Published in: Software
  • Be the first to comment

  • Be the first to like this

EF Core in Containerized ASP.NET Core APIs

  1. 1. USING EF CORE IN CONTAINERIZED ASP.NET CORE APIS JULIE LERMAN THEDATAFARM.COM @JULIELERMAN
  2. 2. Container Application + resources combined into a self-contained execution environment
  3. 3. Containers are Not Virtual Machines App Libraries OS Virtual Machine App Libraries Container App Libraries App Libraries App Libraries Docker Engine OS ⚙️Host Infrastructure ⚙️⚙️ Host ⚙️ Infrastructure Container Container Container
  4. 4. Docker Engine
  5. 5. PREPARING VISUAL STUDIO FOR DOCKER • Install Docker for Windows • Use Linux Containers (default) • Specify a shared drive in settings • Install VS Container Tools Extension • Note: There is also an A+ Docker extension for VS Code
  6. 6. EF CORE USING SQL SERVER LOCALDB IN KESTREL THEN WITH DOCKER
  7. 7. Dockerfile Text file Defines image contents & runtime instrux Docker Image Binary file composed of app and dependencies Docker Container Running instance of an image Class definition Binary form of class Object instance docker build docker run
  8. 8. USING AZURE SQL & PROTECTING SECRETS
  9. 9. Directory with code & DockerFile docker-compose.yml Container 1 Definition build image using this DockerFile Container 2 Definition use pre-existing image XYZ Container 3 Definition build image from some other DockerFIle Existing XYZ image e.g., SQL Server for Linux
  10. 10. AZURE SQL WITH DOCKER-COMPOSE • Define ENV connection string in DockerFile. Gets stored in the image • String has placeholders for user id and password • Declare user & password environment variables in docker-compose.yml • Hide user & password values in .env file. Local to host machine only • Replace placeholders with real values • Can use local database when running in Kestrel on local computer, not in Docker via connection string in appsettings
  11. 11. USING SQL SERVER IN ITS OWN CONTAINER
  12. 12. SQL SERVER IN CONTAINER WITH DOCKER-COMPOSE • Define ENV connection string in DockerFile. Gets stored in the image • Declare password environment variables in docker-compose.yml • Define db container in docker-compose with “depends on” • Hide user & password values in .env file. Local to host machine only • Connection string server name = name of db service • Can use local database when running in Kestrel on local computer, not in Docker
  13. 13. 3 part article detailing all of these steps in MSDN Magazine bit.ly/datapointsefdocker
  14. 14. bit.ly/2nhq1QU dockr.ly/2lEHouh
  15. 15. Demo code at: github.com/julielerman/EFCoreInDocker_BASTA2019
  16. 16. USING EF CORE IN CONTAINERIZED ASP.NET CORE APIS JULIE LERMAN THEDATAFARM.COM @JULIELERMAN

×