Getting started with Azure Kubernetes Series — Part 2

rahul sahay
4 min readSep 23, 2019

--

Hi Friends,

This is the continuation of the Azure Kubernetes series. In this section, we will continue from the last place and we will see how to use docker compose for stitching multiple apps together.

Docker-compose comes handy when we need to combine multiple services in one file. Let’s look at the sample compose file and what benefits we can get using compose.

Here, I have below mentioned things.

  • First comes version
  • Then, services section start, where in first piece is sql.data-client. This will be used in Kubernetes deployment. Will discuss this later.
  • We have sql.data section, wherein my sql related settings go. These are the same commands which we used previously.
  • We have application front-end. In this case, ASP.NET MVC application, which is tagged inside AKSWeb section. Here, context means where application is sitting and then it should pick the dockerfile from that location. It also has depends_on section, where in I mentioned that it depends on AKSApi project. Then we have ports, its also the same thing which we have used initially. Lastly, I have AKSApiUrl which is having api link of our API project
  • Next comes, our AKSApi section, where in we have almost the same setting. Only thing, here we have dependency on sql.data section. Then, we have port running on 8081 and lastly, we have environment section, where in connection string goes.

Once, I have every thing in place, I can simply go and run docker-compose build, if I have the file with the same name.

Once successfully built, it will flag success message like shown below.

Note:- Anything we are writing in dockerfile or docker-compose file is case sensitive, since we are building the same on Linux version. Hence, careful with that.

Build process will follow the same dependency how we specified in docker compose file. Again this is build time configuration not the run-time. I can spin up all these together with docker-compose up command. But, before that if I have any container running with the same name like sql1, then I need to stop that and remove first and then continue with docker-compose up command.

Here all the instances are running fine.

This approach is ok. But, very confusing sometimes. These are all custom built images, which is having dependency on one and another. Therefore, there has to be new approach.

With docker-compose file, I can go ahead and split single big docker-compose file into multiple docker-compose files for build time, run time and final image. Below is the snippet for the same.

And final docker-compose file for the same.

Here, we specify -f flag for filename. Once build successfully completed, then again it will flag message like shown below.

We have built the images. In order to run the same, we can use below command.

Upon successful run, it will come like

Now, in the next section, we will be looking at container orchestration. Till then stay tuned and happy coding.

Thanks,

Rahul

In case, if you have any query, you can reach out to me @ https://twitter.com/rahulsahay19

--

--

rahul sahay
rahul sahay

Written by rahul sahay

🌟 Unleashing the Power of Languages! 🚀 Expert polyglot developer, author, and Course creator on a mission to transform coding into an art. 🎨 Join me in

No responses yet