After the my-python-app image is built, you can run it as a container:
docker run -p 5000:5000 dockerize.py
The application is then started as a container, after which the name parameter sends the name to the container and the -p parameter maps the 5000 host port to the container port of 5000.
Next, you need to open your web browser, then on the address bar, type localhost: 5000. If everything worked the right way, then you should see the following web page:
Docker runs the dockerize.py container by using the run command, and the result is a web application. The image contains the instructions necessary for the operation of the container.
The correlation between container and image can be understood by referring to the object-oriented programming paradigm by associating the image with a class and the container with the class instance.
It is useful to recap what happens when we create an instance of a container:
- The image of the container is (if not already present) unloaded locally.
- An environment in which to start the container is created.
- A message is printed on the screen.
- The previously created environment is then abandoned.
This all takes place in a few seconds and with a simple, intuitive, and readable command.