Building a Docker Backend for Xamarin Mobile Development Series 4


Précis

While I was speaking at Techorama in Belgium I met up with fellow speakers and MVP colleagues in the speaker room while prepping for sessions I had to deliver.  We sort of captured a table and that’s where all the SharePoint Office Server and Services MVP congregated; often times it’s a combination of Andrew Connell, Liam Cleary, Vincent Biret, Thomas Votchen, Elio Stryuf Spencer Harbar, Paolo Pialorsi and a few others. When you have that many experts and community folks in one area you are going to learn about technologies that you have always wondered about, but based on your discipline [focus area], you may not have time to explore… one of the topics that resonated with me was DockerAndrew Connell had a few demos he was doing where he spun up Docker containers for a Web App and Database and something else that I cannot remember now, I just know it was 3 connected containers that he had a YML script to spin up and down as needed. Once I heard his story about how he now uses Docker Containers rather than VM’s whenever possible, and I learned about the portability, efficiencies, and ease of use, I was hooked. For me, I was already thinking about how I could leverage this in my Xamarin sessions and demos; I was thinking that by large a Xamarin.Forms app is really rooted in creating an App that has an experience rooted in a Data Store front ended by a Web API that a standard .NET Mobile project taps into.  I was thinking this could be another way to do that and reduce some of my Azure cost when I have to spin up an App Service and SQL Azure instance to support my Xamarin mobile app.  After getting the Kool Aid from AC, I started off on some Pluralsight courses by Dan Wahlin , Nigel Poulton, and Kevin Dockx (see below links to the courses) to get ramped up and I took this weekend to master it. While I am not completely there yet… I am 65% complete i.e. to say I have my database container, my Web API (not yet in a container) but communicating with my microsoft/mssql-server-linux Docker container… and all I have to do now is get those container talking to each other and then expose the Web API to my Xamarin.Forms app. 

This blog post (well series) will walk you through that experience. This post will serve as the anchor for the series and I will be updating it as I go. I am not sure what the final outcome will be. In the end, I expect to have a Xamarin App consuming from a backend built on Docker Containers, as I now work for K2, I also plan to integrate K2 Smart Form as a Non Mobile Front End that will also communicate with the Docker Container Back End.

Strap in…

Recipe

Lets create a legend so you can follow where I am at any point in time. subject to modification as needed

BOLD – Items Done
Italics – Work in Progress (WIP)
Grey Subdued Font – Not Started

The Plan of Action in my mind so far is to:

  1. Install Docker for Mac
  2. Get base Docker Images to host the Web API and Database
    1. microsoft/aspnetcore
    2. microsoft/mssql-server-linux
  3. Create Docker Containers for the Xamarin Backend Solution
    1. ASP.NET Core for the Web API with Entityframework Core to the MSSQL Linux Database
    2. Provision the Database and Tables using Code First EF Core in my MSSQL Linux Database
  4. Modify those base images to include
    1. the Code for my ASP.NET Core Web API
    2. the database and tables for the SQL Database that the Web API will be pulling from
  5. Create a Docker Network and include both of my Modified Docker Containers  –
  6. Host and Expose the Web API Container URI in my Azure Tennant or maybe even somewhere else.. that’s the idea right, I can do this anywhere with containers
  7. Create my Xamarin  Project that consumes the Web API that is hosted in Docker Containers & Publish my iOS and Android App
  8. Integrating with K2 Smart Forms and Brokers directly into Containers or as REST Broker

Links and Help Aids I am using/used

Blog Post are not only to help inform others, but also serve as a reminder of how you [the author ie. me] did things, found resources, so I am building a library here of links I have used to get me where I am. If you know of more please leave me comments. Thank you

  1. Install Docker – I am using a Mac
  2. The new way to do Docker on a Mac does not use Docker Toolbox, it uses Hyperkit and that means you need to download Virtual Box yourself as it is no longer bolted on and Create your Docker Machine Host (linux for me)
  3. Create a Docker Hub Account – optional but makes it easy for you to find Images you can use in your Docker World in order to allow you to create your Containers. My Docker Profile and my stuff are here
  4. I am tracking as much as I can from a Source Code perspective here on my Git Hub Repo
  5. Learning Aids
    1. Nigel Poulton Docker Deep Dive 
    2. Dan Wahlin Docker for Web Developers
    3. Kevin Dockx Build your 1st Web API with ASP.NET Core
    4. Kevin Dockx Deep Dive Course on Web API with ASP.NET Core
  6. Run the SQL Server 2017 container image on Docker on Linux, Mac, or Windows – We use this to get the Image needed for the MSSQL-Server-Linux Docker Image that the Web API will call into
  7. Learn how to communicate with SQL Server on Linux: Connect to SQL Server on Linux and run Transact-SQL queries
  8. If you want to work with the SQL Server on Linux and you are on a Mac, I found the SQL CLI easy to use. So I downloaded it and began using it to inspect what EntityFramework Core was doing behind the scene as I did this Code First and using Visual Studio for Mac which doesn’t have the SQL Toolbox in the IDE.
  9. How to build SQL Connection Strings for the Entity Framework Core
  10. GOTCHA: If you are using ASP.NET Core from Visual Studio for Mac and trying to Connect to a SQL Server in a VM (as I am doing with my Docker Container) you may get an error when the connection is being made that is tied to Open SSL. Here is the fix
  11. Documentation on working with SQL Cli in more detail
  12. A Github Gist I created for my Docker Commands – WIP
  13. Sessions I will be doing to showcase this

Individual Post

Summary

Thank you for taking the time to read through this blog series. The Github Repo where the code is located is here.  The Readme.MD file will walk you through a few ways of how to deploy this solution to your environment. It is my hope after you get through the series that you will be convinced that Docker Containers makes sense over:

  1. Creating VMs in your own Local Dev Rig
  2. Creating VMs in your Cloud Hosting Provider (Azure, AWS, etc)

Learning and Developing solutions is cut down dramatically by using Containers and its is a portable solution as well with scaling built in. If you have any questions or comments, please reach out. Cheers.


Leave a comment

Your email address will not be published. Required fields are marked *

4 thoughts on “Building a Docker Backend for Xamarin Mobile Development Series