In the previous blog post, we explained how to package an application in a container. To illustrate this, we used a simple web application that recognises images, which we executed on a PC and an Azure Container Instance (ACI). In this post, we’ll delve deeper into how to build and package the application.
We wrote the web application from the previous blog post in Go, which supports Windows, Mac and Linux. You can compile Go code with a simple command:
go build -o /usr/bin/app .
This command generates a Linux executable called ‘app’ in the /usr/bin folder. To activate the web application, just start the ‘app’. The web application then becomes available on http://localhost:9090 – or on https://localhost if you’ve configured an SSL certificate. Remember that this web application only works on Linux and Mac OS because it contains several dependencies that aren’t compatible with Windows.
As a developer, you can test and execute the application locally without using containers. Be sure to look at the code as well.
As a developer, you’re in charge of packaging the web application in a container. You can use the application’s own workstation for this. If you want to build a container, you’ll need the following:
Don’t forget to read the Docker file with instructions for the web application.
This Docker file does the following:
With the Docker file and the code in the same folder, you can use the following command to build the container image:
docker build -t xylos/nasnet .
This command will download the tensorflow/tensorflow:1.12.0 image if you haven’t used it already. After completing the download, follow the instructions in the Docker file and save the result in a new container image titled xylos/nasnet.
You can now use the following command to test the container image on its workstation:
docker run -p 80:9090 -d xylos/nasnet
This command makes the web application available on http://localhost. If everything works as desired, you can save the container image in a Docker repository by using the following command:
docker push xylos/nasnet
Docker knows that we’ll want to use a public registry, so it’ll request the user’s (in this case: Xylos’) login information.
Private registries are fully compatible with the existing Docker tools, so developers can continue using their usual toolkit.
We’ve discussed how you as a developer can build a container image and store it in a container registry. You can build, test and upload the container image using its own workstation. If you want to put the application into production, you’ll need to use Kubernetes and CI/CD (Continuous Integration/Continuous Deployment).
Ready for the next step? In the next blog posts, we’ll explain how to Azure Kubernetes Service (AKS) to put containers into production and we’ll talk about Azure DevOps as a CI/CD solution.
Your email address will not be published. Required fields are marked.