Google Cloud Platform (GCP) - How to create docker container
Google Cloud Platform Let's understand what we will cover today. So first, we will understand container basics.
This would be a quick overview. Then we'll understand the containerization process, how a containerization process works. Then we will understand what all components we have used in this demonstration. And finally we will see the container basics. So in a very simple term, containerization technology is a method to package an application within a capsule with all its dependency. So it becomes kind of an indent identity which can be shipped from one environment to another environment. You can see in the architecture diagram how the physical hardware and the physical It sector is hosted on the server.
Then on top of it, there is a host OS. And on top of it there is a Docker engine. This Docker engine does the magic of wrapping various applications into containers. Those containers can then be shipped with minimal dependencies across platforms. So this is a very, very basic understanding of containers. So what is a containerization process? So basically there are five simple steps to understand how containerization works, and these five simple steps we will follow in our exercise as well. So let's understand how. So the first step, what we will follow is we will code our application.
So basically, in order to containerize something, first you have to develop your application. So at step one, we'll create a simple application by writing code. After that comes the Docker file. Now, this Docker file is a static file with a set of instructions to instruct the Docker engine about the dependencies which are required for this particular application to run within a container. So this Docker file, combined with this application, then is used in step three, which is to build a container image. So a container image can only be built once we have our application code along with the Docker file with all the instructions.
The step four is to push this particular container image onto a container registry. So this container registry is a shared pool of various container images, and you can continuously use this registry as a common pool for storing all your container images. And you can push the images into this registry and also pull the images from this registry as well. And finally, when you want to run this particular container, you will do it on this particular technology, which is in step five. You will do it under Cloud Run.
So Cloud Run is a stateless, fully managed application provided by Google Cloud specifically to run containerized applications. So we'll understand that in detail once we go into the demo. But this is a high level overview of how specific containerization process works. It might vary from case to case slightly, but overall this is the process which we will follow today. So now we will understand what what are the basic components used in this exercise? Obviously, there might be some components you are aware of, some component which you might hear for the first time.
But the thing is, once you understand a basic, you can always go back and do your homework. So first of all, we'll use Python to code application. We'll write a very simple application like Hello Gold, and then we will use Cloud Shell. Now what is Cloud Shell? Cloud Shell is kind of a lightweight Linux virtual machine that runs within your Google Cloud platform, and you can use it for running any application or for creating any containers, because it comes with all the preinstalled utilities like G Cloud, which is a command-line utility.
Also, you have Docker installed already, this particular shell, so you don't need to do that prerequisite. If you want to do it on your machine, then you have to install Google Cloud SDK. Now Google Cloud SDK has to be installed. First you have to install then all the utilities coming with that SDK to further use this process. But we will save time and we'll directly use Cloud Shell in this particular case. Docker file. As I said, it contains a set of commands to be used for building Docker container image.
Finally, the container image would be the file with all the executable and the application code which will then be pushed into Container registry. Now container Registry, as I said, is a shared repository for storing contain images. Cloud Run also is a fully managed service to run containerized replication. As we have already understood, we will also be using Flask. So what is Flask? Flask is a web framework, very lightweight web framework written in Python, which can help you create very lightweight web application, like a blog or a Wiki page.
So we will use Flask in this because we are creating a very, very lightweight application. Unicorn is Green Unicorn, and it is an HTTP server which comes in Unix. So we will use this particular HTTP server to deploy our application and we will access it via this particular HTTP server. Wsgi stands for Web Service Gateway interface. So it is basically deploying any kind of web service or web applications. G cloud. As I said, it's a command-line interface tool used for managing Google Cloud products and services.
It's time for the demo.
So let's start.
So first I will log into my Google Cloud console. Now there are some basic steps which we have to follow, which will include certain Linux commands as well. If you're not well versed with Linux, these are very basic commands which I'll explain over the course of a few minutes while we are performing this exercise. But if you want me to make a separate video on basic Linux commands, do let me know. I'll try to make something for you, but these are very basic commands which you should know, and these are used in DayToday work or Unix.
So pretty much whatever you do on your Google Cloud platform would start by creating a project if you already have a project Valen board. But if you have not, which I have intentionally not created yet because I wanted to show you guys. So first thing is, you have to create a project. Whatever you, whatever resources you will utilize, whatever billing charges will occur will occur based on the usage you do within this project. So let's create our project. So let's create a new project. Let me name it as YouTube Container demo.
So this is my project name, YouTube Container demo. So I'll create this. So, guys, now our project is ready. And this is the dashboard which shows the overall activity of our dashboard. And just to let you know, this is my demo account. So I have got $300 credit which I can utilize. And you can also create your own account using the one year trial period. So now what we have to do is, as I told you in our slides, that we will do all our activity using a cloud shell, which is a lightweight virtual machine running within this platform.
To help us run certain basic command-line utilities for which we don't need to install or configure Docker or install Google Cloud SDK. We can simply click on this icon which says Activate Cloud shell. So we click on this. And just to let you know, I have opened this intention incognito so that there is no history of previous Google accounts used. So better to use this way. Now this particular cloud shell is opening up for my project. All right. So you can click on this icon and open it in the separate window, because that would be much easier.
So now you can see I'm logged into my cloud shell, you can see my user ID and the project name we have just created. So first thing what we will do is create a new directory using Mkdir command. And the name of this directory would be similar to what we are trying to achieve. So I'm trying to create a Hello YouTube application based on Python language. So I'll name it. Hello, YouTube Python. So now I'll go into this directory using CD command, and I have just clicked on the tab which auto complete the location, so you don't need to type it.
So just keep a note. Obviously, these are Linux shortcuts. So now we are into the directory. So first thing which we have to do is to code our app. As per our first app, we have to code our app. Obviously, this is not a coding exercise. So the code which I'm using is a very simple code which is already built. And I'll show you what it is. We'll go through the functionality of that code, and we'll then create it. So we'll create a new file, app Pi.
So for that, the command which we use is touch. Touch creates a new file. So I'll do app Pi. So now I should have app Pin here. Ok, so now we have it. What we have to now do is to open this file and enter the content of the code which we want to run. So it's a Python code. So we will use Nano editor. So Nano is an editor. It is kind of an editor to edit any file or enter any data modify. I need it in any file, so I just copy this.
Paste it here. Enter. So now I'll just take the code. All right.

0 Comments