{"id":107452,"date":"2022-02-21T11:00:00","date_gmt":"2022-02-21T09:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=107452"},"modified":"2022-02-16T14:11:17","modified_gmt":"2022-02-16T12:11:17","slug":"run-docker-commands-in-python","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/","title":{"rendered":"Run Docker Commands in Python"},"content":{"rendered":"<p>Hello in this tutorial, we will create a simple python flask application and run the docker commands from the python script.<\/p>\n<h2>1. Introduction<\/h2>\n<p><strong>Flask<\/strong> in python programming helps to build web applications. It is easier than Django\u2019s framework and requires less base code to implement a simple web application. To set up the application we\u2019ll first require to install python.<\/p>\n<h3>1.1 Setting up Python<\/h3>\n<p>If someone needs to go through the Python installation on Windows, please watch <a href=\"https:\/\/www.youtube.com\/watch?v=i-MuSAwgwCU\" target=\"_blank\" rel=\"noopener\">this<\/a> link. You can download the Python from <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noopener\">this<\/a> link.<\/p>\n<h3>1.2 What is Docker &amp; Setting up Docker<\/h3>\n<p>In the present world, <strong>Docker<\/strong> is an important term,<\/p>\n<ul>\n<li>Often used in CI\/CD platform that packages and runs the application with its dependencies inside a container<\/li>\n<li>Is a standard for Linux Containers<\/li>\n<li>A <em>Container<\/em> is a runtime that runs under any Linux kernel and provides a private machine-like space under Linux<\/li>\n<\/ul>\n<p>If someone needs to go through the Docker installation, please watch <a href=\"https:\/\/www.youtube.com\/watch?v=R-ZMkGvh-9Y\" target=\"_blank\" rel=\"noopener\">this<\/a> video.<\/p>\n<h2>2. How to run Docker Commands in Python<\/h2>\n<p>I am using <a href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\" rel=\"noopener\">JetBrains PyCharm<\/a> as my preferred IDE. You&#8217;re free to choose the IDE of your choice. Fig. 1 represents the project structure for this tutorial.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerprojectstructureguideimg1.jpg\"><img decoding=\"async\" width=\"407\" height=\"125\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerprojectstructureguideimg1.jpg\" alt=\"\" class=\"wp-image-107453\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerprojectstructureguideimg1.jpg 407w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerprojectstructureguideimg1-300x92.jpg 300w\" sizes=\"(max-width: 407px) 100vw, 407px\" \/><\/a><figcaption>Fig. 1: Application structure<\/figcaption><\/figure>\n<\/div>\n<h3>2.1 Creating a requirements file<\/h3>\n<p>Add the below code to the requirements file. The file will be responsible to download and install the packages required for this tutorial.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>requirements.txt<\/em><\/span><\/p>\n<pre class=\"brush:plain;\">Flask\n<\/pre>\n<h3>2.2 Basic input html form<\/h3>\n<p>Define an HTML form in the <code>templates<\/code> folder with two input fields responsible to accept the name and tag required for the <code>docker pull \u2026<\/code> command. This page will also show the success or error messages once the operation is completed.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>index.html<\/em><\/span><\/p>\n<pre class=\"brush:html;\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n    &lt;head&gt;\n        &lt;meta charset=\"UTF-8\" \/&gt;\n        &lt;title&gt;Index&lt;\/title&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;h1&gt;Python Docker client implementation&lt;\/h1&gt;\n        &lt;hr&gt;\n        &lt;p&gt;\n            {% with messages = get_flashed_messages() %}\n              {% if messages %}\n                &lt;ul class=flashes&gt;\n                {% for message in messages %}\n                  &lt;li&gt;{{ message }}&lt;\/li&gt;\n                {% endfor %}\n                &lt;\/ul&gt;\n              {% endif %}\n            {% endwith %}\n        &lt;\/p&gt;\n        &lt;form action=\"\/\" method=\"POST\"&gt;\n            &lt;label for=\"name\"&gt;Image name:&lt;\/label&gt;\n            &lt;input type=\"text\" id=\"name\" name=\"name\" placeholder=\"Enter image name\"&gt;\n            &lt;br&gt;\n            &lt;label for=\"tag\"&gt;Tag:&lt;\/label&gt;\n            &lt;input type=\"text\" id=\"tag\" name=\"tag\" placeholder=\"Enter tag\"&gt;\n            &lt;input type=\"submit\" value=\"Submit\" \/&gt;\n        &lt;\/form&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<h3>2.3 List images html<\/h3>\n<p>Create an HTML page in the <code>templates<\/code> folder that will show the list of docker images available in the machine. The page is accessible from the following endpoint &#8211; <code>\/images<\/code>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>images.html<\/em><\/span><\/p>\n<pre class=\"brush:html;\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n    &lt;head&gt;\n        &lt;meta charset=\"UTF-8\" \/&gt;\n        &lt;title&gt;Images&lt;\/title&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;h2&gt;Available images&lt;\/h2&gt;\n        &lt;hr&gt;\n        &lt;p&gt;\n            &lt;span&gt;Total images= &lt;\/span&gt;{{data|length}}\n        &lt;\/p&gt;\n        &lt;ul&gt;\n            {% for ele in data %}\n            &lt;li&gt;{{ ele }}&lt;\/li&gt;\n            {% endfor %}\n        &lt;\/ul&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<h3>2.4 Python code<\/h3>\n<p>The python file will expose four different endpoints responsible for interacting with the frontend pages.<\/p>\n<ul>\n<li><code>\/<\/code> endpoint &#8211; Responsible for showing the HTML page to the user via the HTTP GET call. The same endpoint will also be responsible to handle the HTTP POST call from the form and execute the <code>docker pull<\/code> command to fetch the required image from the docker repository<\/li>\n<li><code>\/images<\/code> endpoint &#8211; Responsible to run the <code>docker images<\/code> command and show the result on the <code>images.html<\/code> page<\/li>\n<li><code>\/remove<\/code> endpoint \u2013 Responsible to remove the image. I have skipped this functionality for users to play<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline;\"><em>main.py<\/em><\/span><\/p>\n<pre class=\"brush:python;\">import logging\nimport os\nimport subprocess\n\nfrom flask import Flask, render_template, request, redirect, flash\n\n# [logging config\nlogging.basicConfig(format='%(asctime)s:%(levelname)s:%(filename)s:%(funcName)s:%(message)s',\n                    datefmt='%Y-%m-%d %H:%M:%S',\n                    level=logging.INFO)\n# logging config]\n\napp = Flask(__name__)\napp.secret_key = \"somesecretkey\"\n\n\n# http:\/\/localhost:5000\n@app.route('\/', methods=['GET'])\ndef index():\n    logging.info('Showing index page')\n    return render_template('index.html')\n\n\n@app.route('\/', methods=['POST'])\ndef pull():\n    image_name = request.form.get(\"name\")\n    tag = request.form.get(\"tag\")\n    try:\n        updated_tag = tag if len(tag.strip()) &gt; 0 else 'latest'\n        logging.info('Pulling image= [%s] with tag= [%s]', image_name, updated_tag)\n        sub_cmd = 'docker pull {img_name}:{tag}'.format(img_name=image_name, tag=updated_tag)\n        subprocess.run(sub_cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n        flash(f'{image_name} pulled successfully from Docker hub')\n    except subprocess.CalledProcessError as error:\n        if \"repository does not exist\" in error.stderr.decode(\"utf-8\"):\n            flash(f'{image_name} not found in Docker hub')\n            logging.error(error)\n        elif \"not found\" in error.stderr.decode(\"utf-8\"):\n            flash(f'{image_name} not found for {tag} tag in Docker hub')\n            logging.error(error)\n        else:\n            flash('Something unexpected has occurred. Check app logs')\n            logging.error(error)\n\n    return redirect('\/')\n\n\n# http:\/\/localhost:5000\/images\n@app.route('\/images', methods=['GET'])\ndef images():\n    logging.info('Listing images')\n    sub_cmd = 'docker images --format \"Id= {{.ID}}; Name= {{.Repository}}; Tag= {{.Tag}}\"'\n    # with open('output.txt', \"w\") as outfile:\n    #     subprocess.run(sub_cmd, shell=True, check=True, stdout=outfile, stderr=outfile)\n    res = subprocess.run(sub_cmd, text=True, stdout=subprocess.PIPE).stdout.splitlines()\n    return render_template('images.html', data=res)\n\n\n# http:\/\/localhost:5000\/remove\n@app.route('\/remove', methods=['POST'])\ndef remove():\n    raise Exception('Not yet implemented.')\n\n\nif __name__ == '__main__':\n    # Development only: run \"python app.py\" and open http:\/\/localhost:5000\n    server_port = os.environ.get('PORT', '5000')\n    app.run(debug=False, port=server_port, host='0.0.0.0')\n<\/pre>\n<h2>3. Code run Docker Commands in Python demo<\/h2>\n<p>For localhost debugging, you can run the application by running the <code>main.py<\/code> py file in the PyCharm IDE. The application will be started on the <code>5000<\/code> port number and you can hit the following url &#8211; <code>http:\/\/localhost:5000<\/code> in the browser of your choice to display the index HTML page.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide1.jpg\"><img decoding=\"async\" width=\"703\" height=\"181\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide1.jpg\" alt=\"\" class=\"wp-image-107454\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide1.jpg 703w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide1-300x77.jpg 300w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><\/a><figcaption>Fig. 2: Welcome page<\/figcaption><\/figure>\n<\/div>\n<p>Enter the details in the input fields and click the submit button. For the demo, I have entered the image name as &#8211; <code>hello-world<\/code> and tag as &#8211; <code>latest<\/code>. Once the image is downloaded successfully a success message will be shown as in Fig. 3.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide2.jpg\"><img decoding=\"async\" width=\"723\" height=\"212\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide2.jpg\" alt=\"\" class=\"wp-image-107455\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide2.jpg 723w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide2-300x88.jpg 300w\" sizes=\"(max-width: 723px) 100vw, 723px\" \/><\/a><figcaption>Fig. 3: Pulling docker image<\/figcaption><\/figure>\n<\/div>\n<p>In case of failure, the error message will be shown on the same page. Now to verify whether the image was downloaded successfully or not I have created another endpoint available at <code>http:\/\/localhost:5000\/images<\/code>. This endpoint will trigger the <code>docker images<\/code> command to fetch all the available images in your machine and display them on the html page as shown in Fig. 4.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide3.jpg\"><img decoding=\"async\" width=\"924\" height=\"143\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide3.jpg\" alt=\"\" class=\"wp-image-107456\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide3.jpg 924w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide3-300x46.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/pydockerdemoguide3-768x119.jpg 768w\" sizes=\"(max-width: 924px) 100vw, 924px\" \/><\/a><figcaption>Fig. 4: Images list<\/figcaption><\/figure>\n<\/div>\n<p>Due to security reasons, only the required image is shown while others are cropped. That is all for this tutorial and I hope the article served you with whatever you were looking for. Happy Learning and do not forget to share!<\/p>\n<h2>4. Summary<\/h2>\n<p>In this tutorial, we learned about docker and created a simple python flask application to trigger the docker commands from different endpoints. You\u2019re free to play around with this application and change it as per your needs. You can also download the source code of this tutorial from the <a href=\"#projectDownload\">Downloads<\/a> section.<\/p>\n<h2><a name=\"projectDownload\"><\/a>5. Download the Project<\/h2>\n<p>This was a tutorial on executing docker commands from the python script.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/02\/How-to-run-Docker-Commands-in-Python.docx\"><strong>How to run Docker Commands in Python<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello in this tutorial, we will create a simple python flask application and run the docker commands from the python script. 1. Introduction Flask in python programming helps to build web applications. It is easier than Django\u2019s framework and requires less base code to implement a simple web application. To set up the application we\u2019ll &hellip;<\/p>\n","protected":false},"author":119,"featured_media":99891,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46689],"tags":[1276,1319],"class_list":["post-107452","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-docker","tag-docker-compose"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Run Docker Commands in Python - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In order to run Docker Commands in Python, I am using JetBrains PyCharm as my preferred IDE. The python file will expose four endpoints.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Run Docker Commands in Python - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In order to run Docker Commands in Python, I am using JetBrains PyCharm as my preferred IDE. The python file will expose four endpoints.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-21T09:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"Run Docker Commands in Python\",\"datePublished\":\"2022-02-21T09:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/\"},\"wordCount\":690,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"keywords\":[\"docker\",\"docker-compose\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/\",\"name\":\"Run Docker Commands in Python - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"datePublished\":\"2022-02-21T09:00:00+00:00\",\"description\":\"In order to run Docker Commands in Python, I am using JetBrains PyCharm as my preferred IDE. The python file will expose four endpoints.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"set python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/web-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/web-development\/python\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Run Docker Commands in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Run Docker Commands in Python - Java Code Geeks","description":"In order to run Docker Commands in Python, I am using JetBrains PyCharm as my preferred IDE. The python file will expose four endpoints.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Run Docker Commands in Python - Java Code Geeks","og_description":"In order to run Docker Commands in Python, I am using JetBrains PyCharm as my preferred IDE. The python file will expose four endpoints.","og_url":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2022-02-21T09:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"Run Docker Commands in Python","datePublished":"2022-02-21T09:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/"},"wordCount":690,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","keywords":["docker","docker-compose"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/","url":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/","name":"Run Docker Commands in Python - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","datePublished":"2022-02-21T09:00:00+00:00","description":"In order to run Docker Commands in Python, I am using JetBrains PyCharm as my preferred IDE. The python file will expose four endpoints.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","width":150,"height":150,"caption":"set python"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/run-docker-commands-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/examples.javacodegeeks.com\/category\/web-development\/"},{"@type":"ListItem","position":3,"name":"Python","item":"https:\/\/examples.javacodegeeks.com\/category\/web-development\/python\/"},{"@type":"ListItem","position":4,"name":"Run Docker Commands in Python"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/107452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=107452"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/107452\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/99891"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=107452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=107452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=107452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}