These next two part of the blog series will be admittedly long, there is quite a bit to do, albeit not too complicated, it is tedious with a few intricate steps and a few gotchas to call out. We will start out creating the ASP.NET Core project using a base image hosted in Docker Hub the image we are going to use is the
and we will be layering that base image with our source code to build a new custom image which I have already uploaded in my docker hub profile. This image will have a dependency on another Docker image
however this image will be left at its base, and we will just communicate with it using the ASP.net Core Web API using Code First initially and then through the Web API CRUD methods. Now because this post can be considered TL;DR, I will do a synopsis and short cut to the end ALL YOU WANT is to get a working solution, but in the end, you will have one of two ways to achieve what I have done here
- You can clone my Github Repo which will give the source files to which you can build your own solution and your own custom image. You can then do a docker-compose spin up your own containers with your new custom image. this is a 3 step process outlined in my ReadMe.md file on github
- You can just build the solution based on my custom web api image and the base mssql_linux image by issuing one docker-compose command and this will pull down my image as well as the msssql image and get you going. again, this is all spelled out for you in the ReadMe.md file on github.
Crib Notes Section
If you would just like to get a working copy of this Web API to use, then with the magic of Docker, you can just run a command “dockerc-compose up” inside the directory where this YML file will be located and you are off to the races. Now you will need to have Docker installed on your Mac or Windows machine and for guidance on this you can go to this link. FYI, Docker Compose is installed by default when you install Docker on a Mac or Windows, but on a Linux server, you must install it separately (GOTCHA: more to come on this if you want to install the latest version of Docker Compose on Ubuntu Linux 16.04). Here are the steps to getting this to work on your environment.
- Ensure you have Docker Installed as well as Docker Compose as linked above
- Create a directory on your computer that will become your working directory for the Web API
- Create a file in that directory called “docker-compose.yml”
- Copy and Paste the information from the below image inside that file and Save it
- Issue this command “docker-compose up” from that directory and sit back and watch the magic happen
- Once the process is complete you will/should see an output like below
- Open Chrome Browser [or postman or fiddler] and navigate to http://localhost:8000/api/speakereval and you should be able to hit the API and return the GetALL method. If you try this on Internet Explorer or Firefox it may just try to save down the JSON payload output to your computer.
- In the end, I also wanted this hosted in my Cloud Provider (Azure) and I did basically the same thing I listed in steps 1 through 7 above and I got it hosted here . Note, I may not keep this site up forever and I sure don’t want anyone to be hammering away at it so this link may not last too long.
- There are methods for full CRUD on this WEB API, sorry no SWAGGER definition for you here. but if you go /[id] on the GET method you can get to individual items, if you do the same on a PUT, you can update an item, and if you do the same for a DELETE you can delete an item. If you would like to POST (add) an item, you need to add a header for Content-Type of application/json and that will work too.
In doing it the above way you will get to a working solution in a matter of minutes. This PROVES out the value of Docker which I will go into detail in the summary section. This way DOES NOT provide you my source code, so its basically to get it up and running for consumption. For a detailed way of getting the above done where you where you will have access to my source code, you will make 1 change to the Docker-Compose.yml file and follow steps 1 through 7 above. The change to the YML file will be to remove line number 4 completely. You will be doing this so that Docker will look into the Dockerfile (see image below) and grab the base image of the aspnetcore_build in Docker Hub and build your solution from the Source Code against that. You will get the source Code from my GitHub Repo here and follow the directions on the ReadME.md file there.
For the TL;DR more detailed post where you will learn how to build my solution from the Ground Up. Please see the next post here. to see how we go to this point, please start from the series opener here.
Lets imagine that you wanted to either:
- Experiment a new and exciting technology from the ground up or from an existing solution example
- Lab/Demo/POC out an idea you have in mind
- Work within a team BUT you don’t have similar hardware rigs or environments
- Spin up and Scale out a DEV, POC, Staging, Testing, PROD environment
- Destroy an environment and start over for whatsoever reason
Prime candidate to do it as Docker Containers. The main point here is that you NO LONGER HAVE TO
- Spin up a VM
- Install and Configure an Operating System (Per VM, so imagine if you need a Web Box, a Database Box, other ancillary but necessary Boxes)
- Install Server Software like SQL, IIS, MySQL, Postgres, Apache, Tomcat, you get where I am going…
- Install a Developer Machine in that network so they can communicate and Developer tools like Visual Studio, WebStorm, VSCode, Eclipse, etc..
- Code your solution and do the due diligence if you are working in a team that other team members Rigs are squared away like yours for OS Patch Level, Software Patches and Versions etc.
All this is simplified by just the way the Layered File System works in Docker, they way Docker Compose works and the new capabilities coming online every day with Cloud Providers. For the TL;DR more detailed post where you will learn how to build my solution from the Ground Up. Please see the next post here. to see how we go to this point, please start from the series opener here.