First of all, I was in my docker host which is rhel 9 virtual machine.
Then I created a Python file named app.py
Imported Flask library and routed an app on the “/info” route
And mentioned what to return when someone calls this
Then on my local machine, I pulled a redhat image
Then I run a container named “wos2” on the docker host with the redhat base image
Then I installed Python3.6 & Flask Library on the container in which I want to run my web app.
Then I have copied the app.py file from my local machine to the docker container using this command
docker cp app.py wos2:/code
where app.py is the file in the current machine
wos2 is the name of the container in which I want to copy the image
:/code is the location of the folder in which I want to copy the file app.py
You can check that the app.py file is copied inside the container on the mentioned location
Then I run the app.py file with python3 app.py
You can see this error: We are unable to connect to that specific link.
This is because it is the local host address of the container and this is only accessible inside the container, not outside that.
That’s why we did this.
We add the host as 0.0.0.0
We did this because “0.0.0.0” means the host can be accessible to anyone inside the local host environment.
This command will give out the IP address of the container which is given below, and from that address, we are now able to access the webpage.
Now if we click on this link, and see the webpage, then it is working very fine and we can access our webpage outside the container.