We successfully launched API service using container.
And other than that, we launched one more container and you've seen that it is possible to run API
service in two different containers and access both those API services simultaneously and in such case,
internally in each container Flask web server will be running at the same port 5050.
But you need to expose those internal ports to two different ports on your local computer.
For instance, in one container, this port could be 5050, but in another it must be different.
For instance, 50, 51 or 6000 or something else.
Anything you want.
All right.
Now let's jump inside of the container and have a look at its file system and find inside of the container
working directory that we defined here on this line using workdir instruction and also analyze which
processes are running inside of this container, Please ensure that this container is up and running
and you are able to make some requests to the API server like that.
And now in the new tab, please have a look at the list of containers using Docker PS Command.
Here you'll find the name of the running container and such names are generated automatically by Docker.
In my case, I see such name.
In your case you will see a completely different name, but it is located at the end of this output.
Now, using this name, we will connect to this container using bash process.
One more process will be started and we will be able to get inside of the container using shell.
Let me do that in separate tab.
And if you want to start another process in running container, you need to use command Docker exec.
Next, please add options Dash.
It stands for Interactive and T stands for Terminal and afterwards will be name of the running container.
And in my case, this name is Frosty Beverage.
Let me copy this name from here and paste here.
And after space, please add Bash because we want to run one more process that is called bash.
It is Shell.
Let's now execute such command, and I'm inside of the container.
Here is container ID, and I was placed inside of the working directory slash app.
Let me list files and folders here.
And such files as docker file file file dot log main.py and requirements.txt.
And basically those four files are the same files that are located in the folder in our project here.
Here are those files.
Also accept those four files inside of the app folder should be those hidden files and folders.
Hidden folder and hidden file dot env dot local.
Let's have a look at them as well.
And yes, here is dot vnv folder and dot env dot local file.
But please notice that we discussed before that you should not make dot env dot local file and other
files with environment variables public.
You should keep them only locally on the computer where you run corresponding service.
For instance, front end react application or back end python project doesn't matter.
You should keep them private.
But we see that we actually added such invaded local file to the Docker image and Docker images could
be very easily published, for instance to Docker Hub and anyone might have access to your published
Docker image.
And certainly it's not a good practice to put such sensitive files as files with environment variables
inside of the Docker image.
And if you don't want to do that, you need to use Docker ignore file with list of files that Docker
will ignore and don't add to the Docker image.
But now we are using this Docker image only locally just for development process.
We don't publish such image to Docker hub or other hosting services.
That's why we will keep this file inside of the image and we will not add Docker, ignore and ignore
such file in order to avoid adding it to the image.
This move, when we keep this file inside of the image, allows us to access our API service after we
run it like that with Docker run command and here we only expose port, we publish internal port to
one of the external ports on our computers and we here specify only name of the image.
And this image contains all necessary files, including file with environment variables in order to
be able to run API service as it was run before.
We are still able to access images retrieved from the Unsplash API.
It means that key that is located inside of the local file works as expected.
We use it for request to unsplash API.
Also notice that here inside of this app folder there is sub folder dot env and such folder we created
on purpose before creation of the python virtual environment locally on our computers and such folder
contains such sub folders as being lib and different files and basically inside of the image.
We don't require this dot env folder because as I've told you before, all packages were installed globally
here inside of the container.
And in a moment we will verify that.
That's why it makes sense to add such folder to Docker ignore, but for now we will not do that to keep
it simple.
But please keep in mind that this dot env folder is not required for running our flask web server inside
of the container.
All right.
Key point here is that there is app folder inside of the container.
We could move one level up here and have a look at files and folders here and there are such folders
as home lib media and so on, all folders that are usually present on any Linux like operating system.
And here, along with home dev boot and bin folders, there is app folder with all our project files.
That's why I told you before that you should add such instruction as workdir inside of the Docker file
to put all your application files into separate folder.
Otherwise if you don't add such instruction, all your application files and folders will be placed
here near such folders as home and so on.
And it's not a good practice to do so because at least you could override some folders that are already
present in this root directory here.
All right, now let's analyze Python related installations here.
And first let's have a look at version of the python by entering command Python version and see version
3.9.4.
And that's that exact version, that tech 3.9.2.
We verified it here at Docker Hub.
Tech 3.9 points at the same image as tech three latest and 3.9.4.
That's why we see here exact Python version 3.9.4.
Here it is.
Also could have a look at version of the pap pap version.
And this version is 21 .0.1.
Also told you that Pap installed all dependencies globally inside of the container and that means that
we should be able to access such dependency as flask for instance, globally.
Here inside of the container.
Let's try to check version of the Flask flask dash dash version and get result version of the flask
is 1.1.2.
Same applies to dot env package.
It is also present globally here and it is accessible globally.
If I try to do the same on my computer and enter dot env dash dash version I'll get error command not
found because such package dot env was installed on my computer only inside of the virtual environment.
That's why it is not accessible like that.
But inside of the container we are able to access flask and dot env globally because single purpose
of this container is to run python flask application.
All right, now let's have a look at the processes that are currently running inside of this container.
Please type dash x and you should find list of currently running processes inside of the container and
there are only four of them.
First process with process ID one is called root process, and that is that process that was started
by container initially.
And in our example, command Python plus Main.py was used.
That's why this process is called root process.
And here you see the same command.
This command was entered by us here in the Docker file as last instruction cmd.
Also one more process started here and this process is the same as this one Python Main.py difference
here is that here you see absolute paths and the reason for that is that this process is multithreaded
process.
L here stands for that and this process is root process is session leader.
This small s tells us that also accept Python processes here and here you should see bash process here
on the list.
And we actually started this additional process inside of the container because we opened Bash Shell
here.
That's what you see right now.
It is.
Bash Shell.
Also, we just entered Command X and that's why one more process was created here.
And these are all processes that are running inside of the container.
It is just a single purpose container for running our Python application.
No other processes are present here.
That's the beauty of Docker.
You could create as many containers you want, but each container is single purposed.
Let's now back again to app folder and let's now also have a look at the Requirements.txt file that
is present here in the app directory and recap that this Requirements.txt file was created during image
build process by pipenv.
So let's have a look at it.
Cut requirements dot txt and here are contents of this file and you might find here such dependencies
as flask dash course or flask.
Also there are such dependencies as python dot env and request, but dev packages such as pylint and
black code formatter are absent here in this list.
And I told you before that env does not include dev packages when you generate such txt file out of
file using env LOC requirements command.
But as we verified we were able to successfully run our application because such dependencies as Flask
and flask course are available here and listed in the requirements.txt file.
Great.
Let me show you one more thing.
Let's have a look at main.py file.
And in this file there is such route as new image.
And of course now such main.py file is fully synchronized with Main.py file here in the folder.
But let's try to modify this route for instance, to new image to like that save changes here in this
main.py file.
Go back to container and again have a look at contents of the main.py file and contents here remained
unchanged.
Reason is very simple.
Such main.py file inside of the container is completely different from the main.py file here in the
folder.
And if you want to apply such changes that you made in the folder, you need to rebuild image and rerun
container.
Let's get back to new image root here, as was before.
And now you understand that Main.py file inside of the container is different from the main.py file
inside of the folder in our Visual Studio code project.
All right.
That's how container looks like from inside.
And now let's exit from here.
I hope that idea is fully clear.
And now you understand what happens under the hood when you actually run specific container.
And let me close this tab.
All right.
That's it for this lecture.
And in the next one, let's quickly summarize what we did here, because we are actually done with localization
of the API service.
I'll see you guys after the small pause.