<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Courtney Hackshaw</title>
    <description>The latest articles on DEV Community by Courtney Hackshaw (@davinci784).</description>
    <link>https://dev.to/davinci784</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3414855%2F8dacb0b0-6698-473d-b421-29e93c763e57.jpeg</url>
      <title>DEV Community: Courtney Hackshaw</title>
      <link>https://dev.to/davinci784</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davinci784"/>
    <language>en</language>
    <item>
      <title>Check out this article I wrote on sharing code across Python Microservices</title>
      <dc:creator>Courtney Hackshaw</dc:creator>
      <pubDate>Tue, 05 Aug 2025 17:51:25 +0000</pubDate>
      <link>https://dev.to/davinci784/check-out-this-article-i-wrote-on-sharing-code-across-python-microservices-2355</link>
      <guid>https://dev.to/davinci784/check-out-this-article-i-wrote-on-sharing-code-across-python-microservices-2355</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/davinci784/reusing-shared-code-across-python-microservices-with-poetry-pip-and-docker-51fm" class="crayons-story__hidden-navigation-link"&gt;Reusing Shared Code Across Python Microservices with Poetry, Pip, and Docker&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/davinci784" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3414855%2F8dacb0b0-6698-473d-b421-29e93c763e57.jpeg" alt="davinci784 profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/davinci784" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Courtney Hackshaw
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Courtney Hackshaw
                
              
              &lt;div id="story-author-preview-content-2753728" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/davinci784" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3414855%2F8dacb0b0-6698-473d-b421-29e93c763e57.jpeg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Courtney Hackshaw&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/davinci784/reusing-shared-code-across-python-microservices-with-poetry-pip-and-docker-51fm" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Aug 5 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/davinci784/reusing-shared-code-across-python-microservices-with-poetry-pip-and-docker-51fm" id="article-link-2753728"&gt;
          Reusing Shared Code Across Python Microservices with Poetry, Pip, and Docker
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/docker"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;docker&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/davinci784/reusing-shared-code-across-python-microservices-with-poetry-pip-and-docker-51fm#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>python</category>
      <category>webdev</category>
      <category>docker</category>
      <category>programming</category>
    </item>
    <item>
      <title>Reusing Shared Code Across Python Microservices with Poetry, Pip, and Docker</title>
      <dc:creator>Courtney Hackshaw</dc:creator>
      <pubDate>Tue, 05 Aug 2025 14:04:27 +0000</pubDate>
      <link>https://dev.to/davinci784/reusing-shared-code-across-python-microservices-with-poetry-pip-and-docker-51fm</link>
      <guid>https://dev.to/davinci784/reusing-shared-code-across-python-microservices-with-poetry-pip-and-docker-51fm</guid>
      <description>&lt;h2&gt;
  
  
  Reusing Shared Code Across Python Microservices with Poetry, Pip, and Docker
&lt;/h2&gt;

&lt;p&gt;When building Python microservices, you often end up duplicating utility functions, models, or exception classes across services.&lt;/p&gt;

&lt;p&gt;Instead of duplicating code, you can package shared logic into a reusable module and install it like any other dependency in each microservice.&lt;/p&gt;

&lt;p&gt;In this tutorial, we’ll look at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Structure your project with multiple services&lt;/li&gt;
&lt;li&gt;Extract shared code into a common module&lt;/li&gt;
&lt;li&gt;Use Poetry to manage the shared module&lt;/li&gt;
&lt;li&gt;Use pip + Docker to install it into your services cleanly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the end of this tutorial, you will have a working set up like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-project/
├── shared/ # Shared module managed with Poetry
│ ├── pyproject.toml
│ └── shared/
│   └── main.py
├── apps/
│ ├── app-one/ # Flask app with pip + Docker
│ │ └── main.py
│ └── app-one/ # Flask app with pip + Docker
│   └── main.py
└── docker-compose.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Platform
&lt;/h2&gt;

&lt;p&gt;This article supposes that users will be using MacOS. The equivalent action can be done on any platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Create docker-compose.yml file
&lt;/h2&gt;

&lt;p&gt;We'll use Docker to run our microservices, and define them using a docker-compose.yml file.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;Docker &amp;amp; Docker Compose&lt;/strong&gt;&lt;br&gt;
Docker is a tool to package code and dependencies into isolated containers.&lt;br&gt;
Docker Compose allows you to define and run multiple containers together using a &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s start by creating a Docker Compose file in the root of the project, this can be done with the command &lt;code&gt;touch docker-compose.yml&lt;/code&gt;. Now let's add the code to this file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3.9"&lt;/span&gt;

&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;app1&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./apps/app-one/Dockerfile&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5001:5000"&lt;/span&gt;

  &lt;span class="na"&gt;app2&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./apps/app-two/Dockerfile&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5002:5000"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a quick breakdown of what this file does.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The services key defines the services of the project. When docker builds and runs the project, each service will have its own container&lt;/li&gt;
&lt;li&gt;On the level below the services is the name of each service. In our example, we have two services, &lt;code&gt;app-one&lt;/code&gt; and &lt;code&gt;app-two&lt;/code&gt;. Both are identical.&lt;/li&gt;
&lt;li&gt;The build key has two subkeys, &lt;code&gt;context&lt;/code&gt; and &lt;code&gt;dockerfile&lt;/code&gt;. Context refers to the location that each container will have visibility of the project. In our case, each container will be able to access files in the root of the folder. This will allow them to reference code in the shared folder. The Dockerfile contains instructions Docker uses to build each container image.&lt;/li&gt;
&lt;li&gt;The other subkey of each app is the &lt;code&gt;ports&lt;/code&gt; subkey. This maps a port on your local machine (left side, e.g. 5001) to the container’s internal port (right side, 5000, which Flask uses). So when you visit localhost:5001, Docker forwards that request to port 5000 inside the app1 container.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Create shared module
&lt;/h2&gt;

&lt;p&gt;Now we can create the module that will be shared between each app. Let's start by creating the folder and files using the following command: &lt;code&gt;mkdir shared &amp;amp;&amp;amp; cd shared &amp;amp;&amp;amp; touch pyproject.toml &amp;amp;&amp;amp; mkdir shared &amp;amp;&amp;amp; cd shared &amp;amp;&amp;amp; touch utils.py&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This creates the shared/ folder and an empty &lt;code&gt;pyproject.toml&lt;/code&gt; file, as well as another shared folder with an empty &lt;code&gt;utils.py&lt;/code&gt; file. Now let's add the code to these files. First the utils module, this will be a simple log statement.&lt;/p&gt;

&lt;p&gt;Paste the following code in the &lt;code&gt;utils.py&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;log_info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[SHARED LOG] &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function simply logs a message using &lt;code&gt;logging.info&lt;/code&gt;. We will use this function as the imported code from the shared module.&lt;/p&gt;

&lt;p&gt;Let's now paste the code below to the &lt;code&gt;pyproject.toml&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[tool.poetry]
name = "shared"
version = "0.1.0"
description = "Shared Python code for microservices"
authors = ["Your Name &amp;lt;your_name@email.com&amp;gt;"]
packages = [{ include = "shared" }]
license = "MIT License"

[tool.poetry.dependencies]
python = "&amp;gt;=3.13.5"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;While we use Poetry to manage the shared module, we install it in services using &lt;code&gt;pip install ./shared&lt;/code&gt;. This works because Poetry produces a standard pyproject.toml compatible with pip&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 3: Create app-one service
&lt;/h2&gt;

&lt;p&gt;Let's now create the first microservice. First we need to create the files and folders, from the root directory we run the command &lt;code&gt;cd ../.. &amp;amp;&amp;amp; mkdir apps &amp;amp;&amp;amp; cd apps &amp;amp;&amp;amp; mkdir app-one &amp;amp;&amp;amp; cd app-one &amp;amp;&amp;amp; touch Dockerfile &amp;amp;&amp;amp; touch main.py&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now copy the following code to the main.py file in the app-one folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;shared.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;log_info&lt;/span&gt;

&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;basicConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;INFO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%(asctime)s - %(levelname)s - %(message)s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;log_info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;App1 called home endpoint&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello from App1!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code defines a Flask server application with a home API endpoint which uses the &lt;code&gt;log_info&lt;/code&gt; function from the shared module. This home endpoint will return the text "Hello from App1!". It also creates a log configuration to allow messages to be logged to the console.&lt;/p&gt;

&lt;p&gt;We can now move onto the &lt;code&gt;Dockerfile&lt;/code&gt;, paste this code into this file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# use this image as the base&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.13.5-slim&lt;/span&gt;

&lt;span class="c"&gt;# set the working directory&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="c"&gt;# copy shared Python code&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; shared/ ./shared&lt;/span&gt;

&lt;span class="c"&gt;# install packages in the `./shared` folder's pyproject.toml file&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-cache-dir&lt;/span&gt; ./shared

&lt;span class="c"&gt;# copy the app-one service&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; apps/app-one .&lt;/span&gt;

&lt;span class="c"&gt;# install the flask package&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;flask

&lt;span class="c"&gt;# open port 5000&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 5000&lt;/span&gt;

&lt;span class="c"&gt;# set Flask environment variables&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; FLASK_ENV=development&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; FLASK_DEBUG=1&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; FLASK_APP=main&lt;/span&gt;

&lt;span class="c"&gt;# run the flask app; --host allows external requests; --port uses port 5000 for the flask app, the requests to that port will be forwarded to the running flask app&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["flask", "run", "--host=0.0.0.0", "--port=5000"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Dockerfile is what will be used to create the server for the app-one service. There are descriptive comments which explain what is happening in the configuration of the server in the Dockerfile.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Create app-two service
&lt;/h2&gt;

&lt;p&gt;It's now time to create the app-two service, which will be a mirror of the app-one service. We can make a copy of the app-one folder and make a few changes to it. Let's go back to the apps folder, you should currently be in the app-one folder. If so, type this command in your terminal: &lt;code&gt;cd .. &amp;amp;&amp;amp; cp -R app-one app-two&lt;/code&gt;. You should now have a &lt;code&gt;./apps/app-two&lt;/code&gt; folder as well.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;./apps/app-two/Dockerfile&lt;/code&gt; file, on line 14, replace &lt;code&gt;COPY apps/app-one .&lt;/code&gt; with &lt;code&gt;COPY apps/app-two .&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then , in the &lt;code&gt;./apps/app-two/main.py&lt;/code&gt; file, on line 14, replace the home function with the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;log_info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;App2 called home endpoint&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello from App2!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Run app with Docker
&lt;/h2&gt;

&lt;p&gt;We need to go back to the project root to run the project with Docker. If you followed the instructions above, you would now be in the &lt;code&gt;apps&lt;/code&gt; folder. Run the command &lt;code&gt;cd ..&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can now run the app with &lt;code&gt;docker compose up --build&lt;/code&gt;. Navigate to &lt;code&gt;http://localhost:5001&lt;/code&gt;. You should see "Hello from App1!" in your browser and "App1 called home endpoint" in the Docker logs. Navigating to &lt;code&gt;http://localhost:5002&lt;/code&gt; will show "App2 called home endpoint" in the browser and "Hello from App2!" in the Docker logs.&lt;/p&gt;

&lt;p&gt;By splitting shared logic into a reusable Poetry-managed module, and installing it cleanly into each microservice via Docker and pip, you’ve created a maintainable foundation for working with Python microservices. This pattern prevents code duplication, makes testing easier, and keeps your services modular. From here, you can expand your shared module, add more services, and introduce automated testing or CI/CD workflows to take your system to the next level.&lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>docker</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
