{"id":329294,"date":"2023-09-05T07:00:00","date_gmt":"2023-09-05T07:00:00","guid":{"rendered":"http:\/\/itteacheritfreelance.hk\/wordpress\/?guid=efd2d2146fb6e5c64c3a40f3a87bc4be"},"modified":"2023-09-05T07:00:00","modified_gmt":"2023-09-05T07:00:00","slug":"a-beginners-guide-to-python-containers","status":"publish","type":"post","link":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/2023\/09\/05\/a-beginners-guide-to-python-containers\/","title":{"rendered":"A beginner&#8217;s guide to Python containers"},"content":{"rendered":"<p class=\"syndicated-attribution\"><meta name= \\\"keywords \\\" content= \\\"\u96fb\u5b50\u8a08\u7b97\u6a5f, \u6559\u80b2, IT \u96fb\u8166\u73ed,\u96fb\u8166\u88dc\u7fd2\uff0c \u96fb\u8166\u73ed\uff0c \u5bb6\u6559\uff0c \u79c1\u4eba\u8001\u5e2b\uff0c \u8cc7\u8a0a\u6280\u8853\uff0c \u7a0b\u5e8f\u8a2d\u8a08\uff0c \u96fb\u5b50\u8a08\u7b97\u6a5f\uff0c \u904a\u6232\uff0c \u860b\u679c\uff0c \u96fb\u5f71\uff0c \u8a08\u7b97\u6a5f\uff0c\u7de8\u78bc\uff0c Java\uff0c C\/C++\uff0c JavaScript\uff0c PHP\uff0c HTML\uff0c CSS\uff0c MySQL\uff0c mobile\uff0c Android\uff0c \u52d5\u6f2b\uff0c Python\uff0c teacher\uff0c \u88dc\u7fd2\uff0c \u96fb\u8166\u88dc\u7fd2 \u8cc7\u8a0a, \u7535\u5b50\u8ba1\u7b97\u673a, IT ,Game, apple, movie, Computer,student,Java,\u6559\u80b2, ,\u5b66\u751f, \u5b66\u4e60, learn, \u6559\u5b66,  Android, apple,anime, animation, \u4fe1\u606f\u6280\u672f, \u7a0b\u5e8f\u8bbe\u8ba1, \u79fb\u52a8\u7535\u8bdd, \u8cc7\u8a0a\u79d1\u6280,Game, Jeu, Juego,Call Of Duty ,\u4f7f\u547d\u53ec\u559a , \u6e38\u620f, \u7535\u5b50\u6e38\u620f,, \u591a\u4eba\u7535\u5b50\u6e38\u620f, \u7f51\u7edc\u6e38\u620f\uff0conline\uff0conline game, \u624b\u673a\u6e38\u620f, mobile \\\"><\/p>\n<p><span>A beginner&#8217;s guide to Python containers<\/span><\/p>\n<p><a href=\"https:\/\/developers.redhat.com\/topics\/python\">Python<\/a> has emerged as a go-to language for students, new programmers, and experienced developers. This general-purpose programming language is dynamically typed, memory-managed, and supports multiple programming paradigms. Python is popular for web development, <a href=\"https:\/\/developers.redhat.com\/topics\/data-science\">data science<\/a>, <a href=\"https:\/\/developers.redhat.com\/topics\/ai-ml\">artificial intelligence and machine learning (AI\/ML)<\/a>, scripting for <a href=\"https:\/\/developers.redhat.com\/topics\/linux\/\">Linux<\/a>, and more.<\/p>\n<p><a href=\"https:\/\/developers.redhat.com\/topics\/containers\">Containers<\/a> are a game-changing solution for packaging your code and dependencies, allowing for your application to run quickly and consistently across any environment. Using containers to support your Python application enables efficient development and deployment.<\/p>\n<p>This article shows how to use containers to support your Python applications. We&#8217;ll take a pre-configured application and build a Containerfile for it from scratch. Additionally, we will walk through the importance and implementation of each part.<\/p>\n<h2>Example Flask application<\/h2>\n<p>This tutorial uses an <a href=\"https:\/\/github.com\/ainekeenan\/recipe-image.git\">example Python Flask application<\/a>. When you input a URL for a recipe, it will return links to other recipes with similar &#8220;rare&#8221; ingredients.<\/p>\n<p>If you would like to follow along, <a href=\"https:\/\/docs.github.com\/en\/repositories\/creating-and-managing-repositories\/cloning-a-repository\">clone the example repository<\/a> and <code>cd<\/code> into the <code>\/files<\/code> directory.<\/p>\n<h2>Install Podman<\/h2>\n<p>Podman is a cloud-native, daemonless tool for developing, managing, and running Linux containers. Podman manages the entire container ecosystem from pulling, building, running, and pushing an image. Podman&#8217;s features are based on secure practices, but also minimize the friction between your local development environment and production.<\/p>\n<p class=\"Indent1\"><strong>[ Learn more: <a href=\"https:\/\/developers.redhat.com\/articles\/2023\/03\/01\/podman-desktop-introduction\">What is Podman Desktop? A developer&#8217;s introduction<\/a> ]\u00a0<\/strong><\/p>\n<p>Our Python container will rely on Podman to build our image, run the image, and manage the running container.<\/p>\n<p>To install Podman:<\/p>\n<ol>\n<li aria-level=\"1\">Head to the <a href=\"https:\/\/podman-desktop.io\/\">Podman Desktop<\/a> site and select the download for your environment.<\/li>\n<li aria-level=\"1\">Launch Podman Desktop.<\/li>\n<li aria-level=\"1\">If not already installed, Podman Desktop will prompt you to download <a href=\"https:\/\/docs.podman.io\/en\/latest\/\">Podman<\/a>, the underlying container engine.<\/li>\n<li aria-level=\"1\">Start the Podman machine when prompted by Podman Desktop.<\/li>\n<\/ol>\n<p>Now that we&#8217;ve configured our container engine, let\u2019s build a Containerfile.<\/p>\n<h2>Container parts<\/h2>\n<p>A container will include everything your application needs to run on any machine. The main elements (illustrated in Figure 1) include a base image or platform operating system that you want the system calls to virtualize. You also need your application code. Finally, you need all dependencies, like specific versions of programming language runtimes and libraries your code needs to run.<\/p>\n<div class=\"rhd-c-figure\">\n<article class=\"align-center media media--type-image media--view-mode-article-content\">\n<div class=\"field field--name-image field--type-image field--label-hidden field__items\">\n  <a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/container_layers_.png\" data-featherlight=\"image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/container_layers_.png?itok=L0W6WMOn\" width=\"600\" height=\"318\" alt=\"Layers of a container: Base image, dependencies, and application.\" typeof=\"foaf:Image\" \/><\/a>\n<\/div>\n<div class=\"field field--name-field-caption field--type-string field--label-hidden field__items\">\n<div class=\"rhd-c-caption field__item\">Figure 1: Anatomy of a container: Application code, dependencies, and a base image.<\/div>\n<\/div>\n<\/article>\n<\/div>\n<p>The repository for our recipe website application holds this Containerfile:<\/p>\n<pre>\n<code class=\"language-python\">FROM python\n\nLABEL maintainer=\"akeenan@redhat.com\"\n\nCOPY dependencies.txt dependencies.txt\n\nRUN pip3 install -r dependencies.txt\n\nRUN python3 -m spacy download en_core_web_sm\n\nCOPY . .\n\nCMD [\"python3\", \"-m\" , \"flask\", \"run\", \"--host=0.0.0.0\"]<\/code><\/pre>\n<p>The file <code>dependencies.txt<\/code> contains the following:<\/p>\n<pre>\n<code class=\"language-bash\">flask\n\nbeautifulsoup4\n\nrequests\n\nnumpy\n\npandas\n\nclean-text\n\nspacy<\/code><\/pre>\n<p>Next, let&#8217;s break down the Containerfile and explain why each part is necessary.<\/p>\n<h3>FROM<\/h3>\n<p><code>FROM python<\/code><\/p>\n<p>The first necessary instruction for any Containerfile is <code>FROM<\/code>. <code>FROM<\/code> tells the container system to start a new build stage, or a new creation of an image, using the specified image as a base image.<\/p>\n<p><code>#Syntax for FROM <\/code><\/p>\n<p><code>FROM [--platform=] [AS ] <\/code><\/p>\n<p><code>FROM [--platform=] [:] [AS ] <\/code><\/p>\n<p><code>FROM [--platform=] [@] [AS ]<\/code><\/p>\n<p>You can use the <code>:<tag><\/code> to specify a specific version of an image. For example, to receive the Python version 3.9.17 image, the image argument would look like this: <code>python:3.9.17<\/code>. Tags can be reused, so there is no guarantee the <code>python:latest<\/code> image will be the same as <code>python:latest<\/code> image in 2 months.<\/p>\n<p>If you want to ensure that you are using the same image at all times, you can specify a digest. A digest is a specific image, specified by an ID, that will not change over time. You can obtain a digest ID in the following ways:<\/p>\n<ul>\n<li aria-level=\"1\">By running <code>podman manifest inspect python:<tag><\/code> (Figure 2)<\/li>\n<li aria-level=\"1\">By downloading it from various image repository hubs:\n<ul>\n<li aria-level=\"2\"><a href=\"https:\/\/quay.io\/repository\/centos7\/python-38-centos7?tab=tags\">Quay<\/a><\/li>\n<li aria-level=\"2\"><a href=\"https:\/\/hub.docker.com\/_\/python\">Docker Hub<\/a><\/li>\n<li aria-level=\"2\"><a href=\"https:\/\/catalog.redhat.com\/software\/containers\/ubi8\/python-38\/5dde9cacbed8bd164a0af24a\">Red Hat Ecosystem Catalog<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>If a tag or digest is not specified, the <code>:latest<\/code> tag will be used by default.<\/p>\n<div class=\"rhd-c-figure\">\n<article class=\"align-center media media--type-image media--view-mode-article-content\">\n<div class=\"field field--name-image field--type-image field--label-hidden field__items\">\n  <a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/podman_digest_inspect.png\" data-featherlight=\"image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/podman_digest_inspect.png?itok=UdQ-rEjC\" width=\"600\" height=\"378\" alt=\"Running Podman manifest inspect python:3.9.17 in the terminal will display the digest ID.\" typeof=\"foaf:Image\" \/><\/a>\n<\/div>\n<div class=\"field field--name-field-caption field--type-string field--label-hidden field__items\">\n<div class=\"rhd-c-caption field__item\">Figure 2: Running the podman manifest inspect command in the CLI to get the digest ID.<\/div>\n<\/div>\n<\/article>\n<\/div>\n<h4>FROM scratch<\/h4>\n<p>If you do not want to use a base image\u2014perhaps you want to containerize your own underlying operating system (OS), or you have a very minimal image\u2014you have the option to use <code>FROM scratch<\/code>. The <code>scratch<\/code> image does not include any files or folders; instead, it tells the container system to have the next container instruction to be the first filesystem layer of the image.<\/p>\n<p>Each base image, except for <code>scratch<\/code>, includes an OS that it virtualizes. The default <code>python:<version><\/code> image virtualizes Debian GNU\/Linux, while <code>python:<version>-alpine<\/code> virtualizes Alpine Linux, and <code>python:<version>-windowsservercore<\/code> virtualizes Windows Core OS.<\/p>\n<p>Each operating system has a <strong>user space<\/strong> and a <strong>kernel space<\/strong>. User spaces are processes executed by a user in the operating system. The kernel space manages resources like RAM and Disk.<\/p>\n<p>A container runs in the user space and accesses these resources by system calls. A container abstracting a certain OS will abstract the user space, and perform system calls to the host OS. In your container, the OS virtualizes Linux distributions by having their file systems packaged into a container filesystem. Sharing an underlying virtualized OS allows for a standard environment among containers.<\/p>\n<p>For a Python application, the Python base image works well, including all up-to-date packages you may need. <code>FROM python<\/code> will instruct the container engine to inherit the Python base image. The Python base image will have an underlying OS, the language (Python source code, compiled), the Python runtime dependencies, and <code>pip<\/code>.<\/p>\n<p>If you have a specific OS you would like to virtualize, you can inherit that base image and download Python (more on that later in this article).<\/p>\n<h3>LABEL<\/h3>\n<pre>\n<code>LABEL maintainer=\"akeenan@redhat.com\" <\/code><\/pre>\n<p>A label is used for metadata about a container, using a key=value format. In this label, we use a maintainer key, with the value of. Using a maintainer reference provides a way for developers to reach out to the maintainer if they have questions or feedback about the container. It also gives you a way to take credit for your work.<\/p>\n<h3>COPY<\/h3>\n<p><code>#Copy (local source) (destination in container) <\/code><\/p>\n<p><code>COPY dependencies.txt dependencies.txt<\/code><\/p>\n<p>Now we have our base image and a reference to a maintainer. Our container has an owner, and the basics of the Python language.<\/p>\n<p>The next step is to use <code>pip<\/code> (which is included in the Python base image) to install our dependencies. Any extra library or package a developer downloads is a dependency. In our example Python program, we imported several dependencies, including Flask, BeautifulSoup, and pandas.<\/p>\n<pre>\n<code class=\"language-python\">from flask import Flask, render_template, request\n\nfrom bs4 import BeautifulSoup\n\nimport numpy as np\n\nimport pandas as pd\n\nimport spacy<\/code><\/pre>\n<p>Steps to use the <code>COPY<\/code> instruction:<\/p>\n<ol>\n<li aria-level=\"1\">\n<p>Create a file to hold the names of all dependencies. In the sample application, it is named <code>dependencies.txt<\/code> and looks like this:<\/p>\n<pre>\n<code class=\"language-bash\">#dependencies.txt\n\nflask\n\nbeautifulsoup4\n\nrequests\n\nnumpy\n\npandas\n\nclean-text\n\nspacy<\/code><\/pre>\n<\/li>\n<\/ol>\n<ol start=\"2\">\n<li aria-level=\"1\">The instruction <code>COPY<\/code> will copy your dependency file from your local source into the container. If your file is under another directory, you can include the path or use the <a href=\"https:\/\/www.geeksforgeeks.org\/docker-workdir-instruction\/\">WORKDIR<\/a> instruction.<\/li>\n<li aria-level=\"1\">Inside our local directory, the dependency file is there, named <code>dependencies.txt<\/code>. The instruction <code>COPY dependencies.txt dependencies.txt<\/code> will create a new file named <code>dependencies.txt<\/code> in your container\u00a0and copy over the contents.<\/li>\n<\/ol>\n<h3>RUN<\/h3>\n<p><code>RUN pip3 install -r dependencies.txt <\/code><\/p>\n<p><code>RUN python3 -m spacy download en_core_web_sm<\/code><\/p>\n<p>The <code>RUN<\/code> instruction will execute any commands needed in a new layer on top of our image.<\/p>\n<p>We are using Python 3, so the command in the terminal to use <code>pip<\/code> to install <code><insert-dependency-here><\/code> is <code>pip3 install -r <insert-dependency-here><\/code>.<\/p>\n<p>In our <code>dependencies.txt<\/code> file, we have all packages and libraries that need to be downloaded using <code>pip<\/code>. To shorten the installation process, <code>RUN pip3 install -r dependencies.txt<\/code> will use <code>pip<\/code> to install everything listed in our <code>dependencies.txt<\/code> file.<\/p>\n<p>Additionally, for our sample program, we need to download <code>en_core_web_sm<\/code> using the Python module space. This extra dependency is not installed using <code>pip<\/code>, but we can use an extra <code>RUN<\/code> command to complete the task.<\/p>\n<h3>COPY<\/h3>\n<p><code>COPY . .<\/code><\/p>\n<p>Now we have all dependencies downloaded using the <code>RUN<\/code> instruction, it is time for our application files!<\/p>\n<p>Our Containerfile is hosted in the same directory as our application files. <code>COPY . .<\/code> copies our local directory outside of the container into the local directory inside the container.<\/p>\n<h3>CMD<\/h3>\n<p><code>CMD [\"python3\", \"-m\" , \"flask\", \"run\", \"--host=0.0.0.0\"]<\/code><\/p>\n<p>Every Containerfile must have one\u2014and only one\u2014<code>CMD<\/code> instruction for the container to start. <code>CMD<\/code> provides a default command for an executing container.<\/p>\n<p><code>--host=0.0.0.0<\/code> makes a non-routable meta-address of 0.0.0.0 for the host. It means that the mapping is valid for all addresses\/interfaces of the host.<\/p>\n<p>Normally, you would use the command <code>python3 -m flask run<\/code> to run a Flask application. The same command is used here, in <code><code>CMD [\"executable\",\"param1\",\"param2\"]<\/code><\/code> format.<\/p>\n<p><code>--host=0.0.0.0<\/code> makes a non-routable meta-address of 0.0.0.0 for the host. It means that the mapping is valid for all addresses\/interfaces of the host.<\/p>\n<h2 id=\"alternate_images-h2\">Alternate images<\/h2>\n<p>While the Containerfile above includes the official\u00a0Python image, users can create a Containerfile to support Python in many different ways. Below, the first Containerfile inherits the <a href=\"https:\/\/developers.redhat.com\/products\/rhel\/overview\">Red Hat Enterprise Linux (RHEL)<\/a> Universal Base Image, and then installs Python. The second Containerfile inherits a base image that has combined RHEL and Python dependencies. Users can customize their Python Containerfile to work best for their\u00a0dependencies and target environment.\u00a0<\/p>\n<pre>\n<code class=\"language-python\">#Alternate images that work!\n\n#Red Hat Enterprise Linux UBI, then installing Python\n\nFROM redhat\/ubi8\n\nLABEL maintainer=\"akeenan@redhat.com\"\n\nRUN yum -y install python39\n\nCOPY dependencies.txt dependencies.txt\n\nRUN pip3 install -r dependencies.txt\n\nRUN python3 -m spacy download en_core_web_sm\n\nCOPY . .\n\nCMD [\"python3\", \"-m\" , \"flask\", \"run\", \"--host=0.0.0.0\"]\n\nEXPOSE 5000\n<\/code><\/pre>\n<pre>\n<code>#RHEL UBI + Python in base image\n\nFROM registry.access.redhat.com\/ubi8\/python-311:1-13\n\nLABEL maintainer=\"akeenan@redhat.com\"\n\nCOPY dependencies.txt dependencies.txt\n\nRUN pip3 install -r dependencies.txt\n\nRUN python3 -m spacy download en_core_web_sm\n\nCOPY . .\n\nCMD [\"python3\", \"-m\" , \"flask\", \"run\", \"--host=0.0.0.0\"]\n\nEXPOSE 5000<\/code><\/pre>\n<h2>Build and run the container<\/h2>\n<p>Now that you&#8217;ve written your image, it&#8217;s time to build and run it. We&#8217;ll walk through a few different ways to do this.<\/p>\n<h3>Command-line interface<\/h3>\n<p>In the command-line terminal, in the Containerfile directory, run:<\/p>\n<pre>\n<code class=\"language-bash\"># should have your repo cloned\n\n# ensure you are in the files directory (Cd files)\n\npodman build --tag python-podman .\n\npodman run --publish 5000:5000 python-podman<\/code><\/pre>\n<p><code>podman build --tag python-podman .<\/code> tells Podman to build the image in the current directory and name the image <code>python-podman<\/code>.<\/p>\n<p><code>podman run --publish 5000:5000 python-podman<\/code> will run the <code>python-podman<\/code> image, and publish it on port 5000 outside of the container.<\/p>\n<p>The <code>--publish<\/code> flag has syntax <code>(outside container): (inside container)<\/code>. All Flask applications run on default port 5000, so here we connect our local host (address 127.0.0.1) port 5000 to container port 5000 on address 0.0.0.0.<\/p>\n<p>Now, head to <a href=\"http:\/\/127.0.0.1:5000\/\">http:\/\/127.0.0.1:5000<\/a>, as seen in Figure 5, and enjoy your application! <code> <\/code><\/p>\n<h3>Podman Desktop<\/h3>\n<p>Add to the Containerfile:<\/p>\n<pre>\n<code class=\"language-bash\">EXPOSE 5000<\/code><\/pre>\n<p>When we use the command-line interface, we force our application to be exposed on the localhost port 5000 using the command <code>--publish 5000:5000<\/code>. On Podman Desktop, we just use the GUI, so including this line on our Containerfile will force our application to be exposed on the localhost port 5000.<\/p>\n<p>There are multiple ways to run a container file on Podman Desktop:<\/p>\n<ul>\n<li aria-level=\"1\">Build from Containerfile (Figure 3).<\/li>\n<li aria-level=\"1\">Build on local terminal.<\/li>\n<li aria-level=\"1\">Build from Quay.<\/li>\n<\/ul>\n<div class=\"rhd-c-figure\">\n<article class=\"align-center media media--type-image media--view-mode-article-content\">\n<div class=\"field field--name-image field--type-image field--label-hidden field__items\">\n  <a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/image_from_contianer_file.png\" data-featherlight=\"image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/image_from_contianer_file.png?itok=uhAUCH_q\" width=\"600\" height=\"395\" alt=\"Using Podman Desktop to build a image from Containerfile\" typeof=\"foaf:Image\" \/><\/a>\n<\/div>\n<div class=\"field field--name-field-caption field--type-string field--label-hidden field__items\">\n<div class=\"rhd-c-caption field__item\">Figure 3: Using Podman Desktop to build a image from a Containerfile.<\/div>\n<\/div>\n<\/article>\n<\/div>\n<h4>Build from Containerfile<\/h4>\n<ol>\n<li aria-level=\"1\">Navigate in Podman Desktop to the<strong> Images<\/strong> tab and select <strong>Build an Image<\/strong>, as shown in Figure 4.\n<ol>\n<li aria-level=\"2\">Select the location of your Containerfile.<\/li>\n<li aria-level=\"2\">Select the location of your build directory.<\/li>\n<li aria-level=\"2\">Name the image.<\/li>\n<li aria-level=\"2\">Select <strong>Build<\/strong>, let the image build, and then select <strong>Done<\/strong>.<\/li>\n<\/ol>\n<\/li>\n<li aria-level=\"1\">Click the play button to start the container.\n<ol>\n<li aria-level=\"2\">Name the container.<\/li>\n<li aria-level=\"2\">Click <strong>Start<\/strong>.<\/li>\n<\/ol>\n<\/li>\n<li aria-level=\"1\">Visit the application by selecting the <strong>\u2026<\/strong> icon and <strong>Open in Browser<\/strong>. You will be redirected to localhost:5000, as seen in Figure 5.<\/li>\n<\/ol>\n<div class=\"rhd-c-figure\">\n<article class=\"align-center media media--type-image media--view-mode-article-content\">\n<div class=\"field field--name-image field--type-image field--label-hidden field__items\">\n  <a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/nvm.png\" data-featherlight=\"image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/nvm.png?itok=Rq8CkSBs\" width=\"600\" height=\"395\" alt=\"The Images tab in the Podman Desktop UI with the Pull an image and Build an image buttons.\" typeof=\"foaf:Image\" \/><\/a>\n<\/div>\n<div class=\"field field--name-field-caption field--type-string field--label-hidden field__items\">\n<div class=\"rhd-c-caption field__item\">Figure 4: The Images tab in the Podman Desktop where you can pull and build images.<\/div>\n<\/div>\n<\/article>\n<\/div>\n<h4>Build on local terminal<\/h4>\n<ol>\n<li aria-level=\"1\">In your build context directory, run: <code>podman build --tag python-podman .<\/code>\n<ol>\n<li aria-level=\"2\">In Podman Desktop, under the <strong>Images<\/strong> tab, you will have a image called <code>localhost\/python-podman.<\/code><\/li>\n<\/ol>\n<\/li>\n<li aria-level=\"1\">Click the play button to start the container.\n<ol>\n<li aria-level=\"2\">Name the container.<\/li>\n<li aria-level=\"2\">Click <strong>Start<\/strong>.<\/li>\n<\/ol>\n<\/li>\n<li aria-level=\"1\">Visit the application by selecting the <strong>\u2026<\/strong> icon and <strong>Open in Browser<\/strong>. You will be redirected to localhost:5000, as seen in Figure 5.<\/li>\n<\/ol>\n<h4>Build from Quay (or another image repository)<\/h4>\n<p>If you need to set up your Quay repository, refer to the instructions in\u00a0<a href=\"https:\/\/docs.quay.io\/guides\/create-repo.html#:~:text=via%20the%20UI-,To%20create%20a%20repository%20in%20the%20Quay.io%20UI%2C%20click,the%20'Create%20Repository'%20button.\">this guide<\/a>.\u00a0<\/p>\n<ol>\n<li aria-level=\"1\">In Podman Desktop, under the <strong>Images<\/strong> tab, select the <strong>Pull an Image<\/strong> icon, as shown in Figure 4.\n<ol>\n<li aria-level=\"2\">Enter the name of your image. It will look like this: <code>quay.io\/<username>\/<image-name>\/<\/code><\/li>\n<li aria-level=\"2\">Pull the image.<\/li>\n<\/ol>\n<\/li>\n<li aria-level=\"1\">Click the play button to start the container.\n<ol>\n<li aria-level=\"2\">Name the container.<\/li>\n<li aria-level=\"2\">Click <strong>Start<\/strong>.<\/li>\n<\/ol>\n<\/li>\n<li aria-level=\"1\">Visit the application by selecting the <strong>\u2026<\/strong> icon and <strong>Open in Browser<\/strong>. You will be redirected to localhost:5000, as seen in Figure 5.<\/li>\n<\/ol>\n<div class=\"rhd-c-figure\">\n<article class=\"align-center media media--type-image media--view-mode-article-content\">\n<div class=\"field field--name-image field--type-image field--label-hidden field__items\">\n  <a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/recipe_app_norm.png\" data-featherlight=\"image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_floated\/public\/recipe_app_norm.png?itok=DVAOA6zz\" width=\"600\" height=\"359\" alt=\"The landing page for our web application on localhost:5000\" typeof=\"foaf:Image\" \/><\/a>\n<\/div>\n<div class=\"field field--name-field-caption field--type-string field--label-hidden field__items\">\n<div class=\"rhd-c-caption field__item\">Figure 5: Our Flask application running on localhost:5000.<\/div>\n<\/div>\n<\/article>\n<\/div>\n<h2>Conclusion<\/h2>\n<p>Congratulations! We successfully created a containerized Python application and saw how to run it in multiple ways. If you are working with multiple teams or multiple environments, you can now guarantee that your application will work the same every time you run it.<\/p>\n<p>Whether you are a student, attending a hackathon, doing a personal project, or working on a business, Python and containers are a great place to start coding. Here are a few other resources to check out:<\/p>\n<ul>\n<li><a href=\"https:\/\/developers.redhat.com\/developer-sandbox\/activities\/get-started-with-your-developer-sandbox\">Deploy a sample app on the Developer Sandbox for Red Hat OpenShift<\/a><\/li>\n<li><a href=\"https:\/\/developers.redhat.com\/developer-sandbox\/activities\/build-and-deploy-a-quarkus-application-to-openshift-in-minutes\">Build and deploy a Quarkus application to OpenShift in minutes<\/a><\/li>\n<li><a href=\"https:\/\/developers.redhat.com\/developer-sandbox\/activities\/using-openshift-pipelines\">Using\u00a0OpenShift Pipelines for automated builds and deployment<\/a><\/li>\n<\/ul>\n<p>When it comes time to scale your application, check out <a href=\"https:\/\/developers.redhat.com\/developer-sandbox\/activities\/learn-kubernetes-using-red-hat-developer-sandbox-openshift\">Kubernetes for container orchestration<\/a>.<\/p>\n<p><span><span lang=\"\" about=\"https:\/\/developers.redhat.com\/user\/747017\" typeof=\"schema:Person\" property=\"schema:name\" datatype=\"\" xml:lang=\"\">akeenan<\/span><\/span><br \/>\n<span>Tue, 09\/05\/2023 &#8211; 07:00<\/span><br \/>\n<a href=\"https:\/\/developers.redhat.com\/author\/aine-keenan\" hreflang=\"en\">Aine Keenan<\/a><\/p>\n\n<p class=\"syndicated-attribution\"><figure class= \\\"wp-block-image alignnone \\\"><img src= \\\"http:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-content\/uploads\/2016\/05\/logo2-2.png\\\" alt=\\\"IT\u96fb\u8166\u88dc\u7fd2 java\u88dc\u7fd2 \u70ba\u5927\u5bb6\u914d\u5c0d\u96fb\u8166\u88dc\u7fd2,IT freelance, \u79c1\u4eba\u8001\u5e2b, PHP\u88dc\u7fd2,CSS\u88dc\u7fd2,XML,Java\u88dc\u7fd2,MySQL\u88dc\u7fd2,graphic design\u88dc\u7fd2,\u4e2d\u5c0f\u5b78ICT\u88dc\u7fd2,\u4e00\u5c0d\u4e00\u79c1\u4eba\u88dc\u7fd2\u548cFreelance\u81ea\u7531\u5de5\u4f5c\u914d\u5c0d\u3002\\\"\/><figcaption>\u7acb\u523b\u8a3b\u518a\u53ca\u5831\u540d\u96fb\u8166\u88dc\u7fd2\u8ab2\u7a0b\u5427!<\/figcaption><\/figure>\r\n<\/br>Find A Teacher Form:\r\n<\/br>https:\/\/docs.google.com\/forms\/d\/1vREBnX5n262umf4wU5U2pyTwvk9O-JrAgblA-wH9GFQ\/viewform?edit_requested=true#responses\r\n<\/br><\/br>Email:\r\n<\/br>public1989two@gmail.com<br><br><br><br><br><br><br>\r\n<a href=www.itsec.hk style=color:#FFFFFF;>www.itsec.hk<\/a><br>\r\n<a href=\\\"www.itsec.vip\\\" style=color:#FFFFFF;>www.itsec.vip<\/a><br>\r\n<a href=\\\"www.itseceu.uk\\\" style=color:#FFFFFF;>www.itseceu.uk<\/a><br><\/p>","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>A beginner&#8217;s guide to Python containers<br \/>\nPython has emerged as a go-to language for students, new programmers, and experienced developers. This general-purpose programming language is dynamically typed, memory-managed, and supports multiple programming &#8230;<\/p>\n<\/div>","protected":false},"author":2025,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"A beginner's guide to Python containers - ITTeacherITFreelance.hk","description":"A beginner's guide to Python containers Python has emerged as a go-to language for students, new programmers, and experienced developers. This general-purpose p"},"footnotes":""},"categories":[10700],"tags":[],"_links":{"self":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329294"}],"collection":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/2025"}],"replies":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=329294"}],"version-history":[{"count":1,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329294\/revisions"}],"predecessor-version":[{"id":329295,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329294\/revisions\/329295"}],"wp:attachment":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=329294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=329294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=329294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}