Book Image

Python Microservices Development – 2nd edition - Second Edition

By : Simon Fraser, Tarek Ziadé
Book Image

Python Microservices Development – 2nd edition - Second Edition

By: Simon Fraser, Tarek Ziadé

Overview of this book

The small scope and self-contained nature of microservices make them faster, cleaner, and more scalable than code-heavy monolithic applications. However, building microservices architecture that is efficient as well as lightweight into your applications can be challenging due to the complexity of all the interacting pieces. Python Microservices Development, Second Edition will teach you how to overcome these issues and craft applications that are built as small standard units using proven best practices and avoiding common pitfalls. Through hands-on examples, this book will help you to build efficient microservices using Quart, SQLAlchemy, and other modern Python tools In this updated edition, you will learn how to secure connections between services and how to script Nginx using Lua to build web application firewall features such as rate limiting. Python Microservices Development, Second Edition describes how to use containers and AWS to deploy your services. By the end of the book, you’ll have created a complete Python application based on microservices.
Table of Contents (14 chapters)
12
Other Books You May Enjoy
13
Index

Running Quart in Docker

To run a Quart application in Docker, we can use the base Python image. From there, installing the app and its dependencies can be done via pip, which is already installed in the Python image.

Assuming your project has a requirements.txt file for its pinned dependencies, and a setup.py file that installs the project, creating an image for your project can be done by instructing Docker on how to use the pip command.

In the following example, we introduce the COPY command, which will recursively copy files and directories from outside the container into the image. We also add the EXPOSE directive to indicate to anyone running the container that this port should be exposed to the outside world. We still need to connect that exposed port when we run the container with the -p option. Any process inside the container can listen to any ports that it wants to, and communicate with itself using localhost, but anything outside the container won't be able...