<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alexander Ryabtsev on Medium]]></title>
        <description><![CDATA[Stories by Alexander Ryabtsev on Medium]]></description>
        <link>https://medium.com/@ryabtsev.alex?source=rss-2a5b28db86e2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JRhba1gkzf5YcKoiXBPmfA.jpeg</url>
            <title>Stories by Alexander Ryabtsev on Medium</title>
            <link>https://medium.com/@ryabtsev.alex?source=rss-2a5b28db86e2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:15:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ryabtsev.alex/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Boost Your Mortgage Software Security: Proven Tools and Practices]]></title>
            <link>https://medium.com/@ryabtsev.alex/boost-your-mortgage-software-security-proven-tools-and-practices-a8477601e637?source=rss-2a5b28db86e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8477601e637</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[fintech]]></category>
            <category><![CDATA[mortgage-software]]></category>
            <dc:creator><![CDATA[Alexander Ryabtsev]]></dc:creator>
            <pubDate>Mon, 10 Jul 2023 08:52:53 GMT</pubDate>
            <atom:updated>2023-07-10T08:52:53.932Z</atom:updated>
            <content:encoded><![CDATA[<h4>Fintech Tips and Insights</h4><h4>Preserve critical operations and safeguard your software from different cyberattacks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAaZhekUbcbzl5XlmQxHAA.png" /></figure><p>In an era where the financial sector, particularly mortgage businesses, is increasingly digital, the importance of cybersecurity cannot be overstated. The risk of data breaches in this industry is high, with an average breach cost estimated at $5.72 million, according to <a href="https://www.dataendure.com/wp-content/uploads/2021_Cost_of_a_Data_Breach_-2.pdf">IBM’s 2021 Cost of a Data Breach Report</a>. Prominent companies like Morgan Stanley and HomeTrust Mortgage have fallen victim to cyberattacks, emphasizing the urgent need for advanced cybersecurity practices and software.</p><h3>Benefits of Robust Mortgage Software Cybersecurity</h3><p>Implementing robust cybersecurity measures can significantly reduce risks, ensuring financial stability. Key benefits include:</p><ul><li><strong>Excellent threat detection</strong></li></ul><p>Companies with security awareness training and streamlined processes can respond to threats 3.5 times faster than those without, as highlighted in <a href="https://www.cisco.com/c/en/us/products/security/security-outcomes-report.html#~what&#39;s-new">Cisco’s 2021 Security Outcomes Study</a>.</p><ul><li><strong>Smaller attack surface</strong></li></ul><p>Role-based access control and network security rules help inspect and monitor all network connections, minimizing vulnerability.</p><ul><li><strong>Compliance</strong></li></ul><p>Compliance with industry-wide data security and privacy regulations, including GDPR, PCI DSS, and FTC standards, is vital.</p><ul><li><strong>Reputational integrity</strong></li></ul><p>IBM’s 2021 report shows that the most common types of stolen data were customers’ (44%) and employees’ (26%) personally identifiable information. Safeguarding customer and employee data reduces the likelihood of reputational damage and potential lawsuits.</p><ul><li><strong>Lower cost of data breaches</strong></li></ul><p>Cybersecurity practices like zero trust can cut data breach costs by up to 42.3%.</p><p>→ Read more about <a href="https://djangostars.com/blog/creating-an-online-mortgage-service-tips-and-insights/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=distribution&amp;utm_content=cybersecurity-booking">Successful Mortgage Software</a></p><p><a href="https://djangostars.com/blog/creating-an-online-mortgage-service-tips-and-insights/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=distribution&amp;utm_content=cybersecurity-booking">How to Build a Successful Online Mortgage Service: Tips and Insights</a></p><p>Understanding the tactics employed by hackers is crucial to establishing robust measures to protect against cyber threats.</p><h3>How Criminals Breach IT Security for Mortgage Products</h3><ol><li><strong>Malware injections. </strong>Cybercriminals can run malicious software and scripts within a company’s network. According to the OWASP Top 10, around 94% of applications have suffered from some form of injection.</li><li><strong>Misconfigurations</strong>. Around 94% of applications have broken access control, and 90% of database breaches occur due to poor configuration or open internet accessibility.</li><li><strong>Denial-of-Service (DoS) attack.</strong> These attacks cause systems to overload, resulting in costly downtime.</li><li><strong>Social engineering.</strong> <a href="https://go.checkpoint.com/2022-mid-year-trends/page-trends.php">Check Point’s 2022 Cyber Security Report</a> shows that about 17% of breaches result from psychological manipulation tactics like email phishing and pretexting.</li><li><strong>Ransomware</strong>. Ransomware attacks, which render data inaccessible by encrypting it, increased by 13% in 2021.</li><li><strong>Brute force attacks.</strong> Approximately 5% of breaches occur due to attackers cracking weak passwords and exploiting basic authorization mechanisms.</li></ol><p>Cybersecurity practices can help mortgage companies prevent most data breaches and maintain business continuity by mitigating potential damage.</p><h3>12 Practices to Maximize Cybersecurity for Mortgage Software</h3><blockquote>Typically, mortgage software cybersecurity has weak spots in four layers: the code layer, the third-party layer, the server layer, and the database layer. We pay special attention to these areas when designing and developing fintech solutions.</blockquote><h3>1. Secure password practices</h3><p>Train employees to set long, complex passwords, use unique credentials for different accounts, and never share them with anyone.</p><h3>2. Advanced authentication measures</h3><p>Multi-factor authentication requires providing extra information to access business systems. This approach enables different security layers and reduces potential fraud.</p><h3>3. Device usage policies</h3><p>Companies should enforce the BYOD (bring your own device) policy using business-grade VPN services and anti-malware.</p><h3>4. Access control</h3><p>Implement Role-Based Access Control (RBAC) to restrict system access based on user roles. This also helps trace the origin of data breaches, if they occur.</p><h3>5. Zero trust policy</h3><p>Companies can route traffic through a dedicated firewall, a secured web gateway, or secure access service edge (SASE) platforms. Cisco found that businesses practicing these policies are 35% more likely to excel at SecOps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-H-JxxHKy5NYA3--BbMPsw.png" /></figure><h3>6. Request limits</h3><p>Set limits on packet length and requests to prevent DoS attacks. However, it’s critical to separate actual attacks from increased demand. We use rate-based, regex match, and geographic rules in AWS WAF to block malicious requests on the cloud level.</p><h3>7. Hacking simulations</h3><p>Regularly simulate attacks to anticipate and counter potential threats. Such an approach can give a 30% lift in security performance (compared to companies that practice it only once a year).</p><h3>8. Cloud-based deployment</h3><p>Consolidated cloud-based technologies are much easier to update than distributed, on-premise environments. Over 72% of companies with mature security technology integration and a high degree of automation prefer the cloud. 37% of these organizations deploy cybersecurity tools from a single vendor.</p><h3>9. Proactive technical updates</h3><p>Companies that routinely update security for mortgage products have 30% higher chances of meeting customer demands than those that only do so every few years. After updates, teams should take the time to delete any unneeded functionality, files, or dependencies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BVHT9U7fw6BkvSwI3WCNlg.png" /></figure><h3>10. Unified business architecture</h3><p>Organizations must deconstruct their siloed technology and merge it into highly interconnected systems that act as functional units. This has been shown to improve security program success (11–15%) and threat detection (41%).</p><h3>11. Cyber threat intelligence</h3><p>Threat intelligence software plays a vital role in collecting, organizing, and analyzing security data to provide valuable context for identifying potential signs of compromise and effectively responding to possible attacks.</p><h3>12. Prompt disaster recovery</h3><p>A robust disaster recovery plan should encompass a minimum of 80% of an organization’s critical systems. It is essential for the plan to address various attack vectors and incorporate a comprehensive strategy, such as secure data server backups of source code and critical data, as well as automated encryption measures following a breach.</p><p>→ Read more about <a href="https://djangostars.com/blog/mortgage-tech-trends/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=distribution&amp;utm_content=cybersecurity-booking#header0">Digital Mortgage Software Market Size and Forecasts</a></p><p><a href="https://djangostars.com/blog/mortgage-tech-trends/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=distribution&amp;utm_content=cybersecurity-booking#header0">Discover the top 10 promising mortgage technology trends for 2023</a></p><h3>Technologies to Improve Cybersecurity of Mortgage Platforms</h3><p>The effectiveness of cybersecurity tools greatly depends on their seamless integration into the client’s existing processes. Without proper integration, their efficiency may be compromised. To enhance the cybersecurity of mortgage platforms, the following tools can be instrumental:</p><ul><li><strong>Static Application Security Testing (SAST)</strong> tools like GitHub code scanning and AppSweep scan repositories and check for license compliance.</li><li><strong>Dynamic Application Security Testing (DAST)</strong> tools like OWASP ZAP and StackHawk perform automated vulnerability scanning.</li><li><strong>API security tools</strong> provide runtime security and detect malicious requests.</li><li><strong>SQL protection tools</strong> like Django Object Relational Mapper (ORM) secure data exchange.</li><li><strong>Code quality tools</strong> like MegaLinte and SonarQube check for errors and ensure code consistency.</li><li><strong>Intrusion Detection Systems (IDS)</strong> and<strong> Intrusion Prevention Systems (IPS)</strong> like Datadog and Prisma Cloud inspect traffic for high-risk content, benchmark resource usage, and detect unidentified devices and potential network attacks.</li></ul><p>→ Read more about <a href="https://djangostars.com/blog/digitalize-mortgage-service/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=distribution&amp;utm_content=cybersecurity-booking">Digital Transformation in the Mortgage Industry</a></p><p><a href="https://djangostars.com/blog/innovating-mortgage-industry/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=distribution&amp;utm_content=cybersecurity-booking">Innovating the Mortgage Industry: The Why and the How</a></p><h3>Final Thoughts</h3><p>Any mortgage product or financial software must prioritize proactive cybersecurity. Multi-factor authentication, cloud-based deployment, cyber threat intelligence, and other technologies can help keep key operations running and guard against a wider spectrum of attacks. There is no way to protect systems from all conceivable threats, but an experienced software provider can make them as secure as feasible.</p><p>So if you are looking to <a href="https://djangostars.com/services/python-django-development/">modernize software with top-grade security tools</a> and <a href="https://djangostars.com/services/web-development/">create a secure mortgage app from scratch</a>, our vetted developers, designers, and QA experts can help. <a href="https://djangostars.com/get-in-touch/?utm_source=medium&amp;utm_medium=referral&amp;utm_campaign=distribution">Drop us a call</a> to learn how.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8477601e637" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best Practices of Configuring Django Settings]]></title>
            <link>https://itnext.io/best-practices-of-configuring-django-settings-85e5e770f54b?source=rss-2a5b28db86e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/85e5e770f54b</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Alexander Ryabtsev]]></dc:creator>
            <pubDate>Mon, 08 Apr 2019 10:39:38 GMT</pubDate>
            <atom:updated>2019-10-11T15:08:26.496Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Here I’d like to share the article that brought me to DjangoConEurope 2019 in Copenhagen. This information became a basis for my lightning talk (check the link below to watch video), and, besides thanking </em><a href="https://djangostars.com/company/team/?utm_source=itnext.io&amp;utm_medium=medium&amp;utm_campaign=django%20settings&amp;utm_content=django%20stars%20team"><em>Django Stars Team</em></a><em> for help in preparations and DjangoCon for inviting, I’d like to express the hope you’ll find it useful.</em></p><blockquote><a href="https://2019.djangocon.eu/talks/lightning-talks-day-2/"><strong><em>https://2019.djangocon.eu/talks/lightning-talks-day-2/</em></strong></a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*DBOF0QTRR78Cmbf_ZP2eHA.jpeg" /></figure><h4>Ok, now let’s go to Configuring Django Settings.</h4><p>This article is intended for engineers who use the Django framework. It gives a deep insight into configuring Django project settings, and the pros and cons of different approaches. In the article, you will also find recommendations concerning tools, best practices and architectural solutions, all time-tested and proven by successful projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DM_-9CXVXbejUato.png" /></figure><h3>Managing Django Settings: Issues</h3><p><strong>Different environments.</strong> Usually, you have several environments: local, dev, ci, qa, staging, production, etc. Each environment can have its own specific settings (for example: DEBUG = True, more verbose logging, additional apps, some mocked data, etc). You need an approach that allows you to keep all these Django setting configurations.</p><p><strong>Sensitive data.</strong> You have SECRET_KEY in each Django project. On top of this there can be DB passwords and tokens for third-party APIs like Amazon or Twitter. This data cannot be stored in VCS.</p><p><strong>Sharing settings between team members.</strong> You need a general approach to eliminate human error when working with the settings. For example, a developer may add a third-party app or some API integration and fail to add specific settings. On large (or even mid-size) projects, this can cause real issues.</p><p><strong>Django settings are a Python code.</strong> This is a curse and a blessing at the same time. It gives you a lot of flexibility, but can also be a problem — instead of key-value pairs, settings.py can have a very tricky logic.</p><h3>Setting Configuration: Different Approaches</h3><p>There is no built-in universal way to configure Django settings without hardcoding them. But books, open-source and work projects provide a lot of recommendations and approaches on how to do it best. Let’s take a brief look at the most popular ones to examine their weaknesses and strengths.</p><h3>settings_local.py</h3><p>This is the oldest method. I used it when I was configuring a Django project on a production server for the first time. I saw a lot of people use it back in the day, and I still see it now.</p><p>The basic idea of this method is to extend all environment-specific settings in the settings_local.py file, which is ignored by VCS. Here’s an example:</p><p>settings.py file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e536b79f083aa2bf118382a9b150250f/href">https://medium.com/media/e536b79f083aa2bf118382a9b150250f/href</a></iframe><p>settings_local.py file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67eb01cc3f985d770ffa2c890c0dcac4/href">https://medium.com/media/67eb01cc3f985d770ffa2c890c0dcac4/href</a></iframe><p><strong>Pros:</strong></p><ul><li>Secrets not in VCS.</li></ul><p><strong>Cons:</strong></p><ul><li>settings_local.py is not in VCS, so you can lose some of your Django environment settings.</li><li>The Django settings file is a Python code, so settings_local.py can have some non-obvious logic.</li><li>You need to have settings_local.example (in VCS) to share the default configurations for developers.</li></ul><h3>Separate settings file for each environment</h3><p>This is an extension of the previous approach. It allows you to keep all configurations in VCS and to share default settings between <a href="https://djangostars.com/services/python-django-development/">developers</a>.</p><p>In this case, you make a settings package with the following file structure:</p><pre>settings/<br>   ├── __init__.py<br>   ├── base.py<br>   ├── ci.py<br>   ├── local.py<br>   ├── staging.py<br>   ├── production.py<br>   └── qa.py</pre><p>settings/local.py:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e1c36d83542dc51895fb905edd90f84/href">https://medium.com/media/7e1c36d83542dc51895fb905edd90f84/href</a></iframe><p>To run a project with a specific configuration, you need to set an additional parameter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22b810e8df2b5565e9eed7e160ffefc0/href">https://medium.com/media/22b810e8df2b5565e9eed7e160ffefc0/href</a></iframe><p><strong>Pros:</strong></p><ul><li>All environments are in VCS.</li><li>It’s easy to share settings between developers.</li></ul><p><strong>Cons:</strong></p><ul><li>You need to find a way to handle secret passwords and tokens.</li><li>“Inheritance” of settings can be hard to trace and maintain.</li></ul><h3>Environment variables</h3><p>To solve the issue with sensitive data, you can use environment variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86781819f4d39447dd5e720ad5d4f269/href">https://medium.com/media/86781819f4d39447dd5e720ad5d4f269/href</a></iframe><p>This is the simplest example using Python os.environ and it has several issues:</p><ol><li>You need to handle KeyError exceptions.</li><li>You need to convert types manually (see DATABASE_PORT usage).</li></ol><p>To fix KeyError, you can write your own custom wrapper. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29404ce0ab395eb3cf74348f3dfadad4/href">https://medium.com/media/29404ce0ab395eb3cf74348f3dfadad4/href</a></iframe><p>Also, you can set default values for this wrapper and add type conversion. But actually, there is no need to write this wrapper because you can use a third-party library (we’ll talk about this <a href="https://djangostars.com/blog/configuring-django-settings-best-practices/?utm_source=itnext.io&amp;utm_medium=medium&amp;utm_campaign=django%20settings&amp;utm_content=later#7">later</a>).</p><p><strong>Pros:</strong></p><ul><li>The Configuration is separated from code.</li><li>Environment parity — you have the same code for all environments.</li><li>No inheritance in settings, and cleaner and more consistent code.</li><li>There is a theoretical grounding for using environment variables — <a href="https://djangostars.com/blog/configuring-django-settings-best-practices/?utm_source=itnext.io&amp;utm_medium=medium&amp;utm_campaign=django%20settings&amp;utm_content=12%20factors#6">12 Factors</a>.</li></ul><p><strong>Cons:</strong></p><ul><li>You need to handle sharing default config between developers.</li></ul><h3>12 Factors</h3><p>12 Factors is a collection of recommendations on how to build distributed web-apps that will be easy to deploy and scale in the Cloud. It was created by <a href="https://www.heroku.com/">Heroku</a>, a well-known Cloud hosting provider.</p><p>As the name suggests, the collection consists of twelve parts:</p><ol><li>Codebase</li><li>Dependencies</li><li>Config</li><li>Backing services</li><li>Build, release, run</li><li>Processes</li><li>Port binding</li><li>Concurrency</li><li>Disposability</li><li>Dev/prod parity</li><li>Logs</li><li>Admin processes</li></ol><p>Each point describes a recommended way to implement a specific aspect of the project. Some of these points are covered by instruments like Django, Python, pip. Some are covered by design patterns or the infrastructure setup. In the context of this article, we are interested in one part: the <a href="https://12factor.net/config">Configuration</a>.</p><p>Its main rule is <strong>to store configuration in the environment</strong>. Following this recommendation will give us strict separation of config from code.</p><p>You can read more on <a href="https://12factor.net/">12factor.net</a>.</p><h4>You May Also Like:</h4><ul><li><a href="https://djangostars.com/blog/the-python-celery-cookbook-small-tool-big-possibilities/?utm_source=itnext.io&amp;utm_medium=medium&amp;utm_campaign=django%20settings&amp;utm_content=you%20may%20also%20like">The Python Celery Cookbook: Small Tool, Big Possibilities</a></li><li><a href="https://djangostars.com/blog/what-is-docker-and-how-to-use-it-with-python/?utm_source=itnext.io&amp;utm_medium=medium&amp;utm_campaign=django%20settings&amp;utm_content=you%20may%20also%20like">What is Docker and How to Use it With Python (Tutorial)</a></li></ul><h3>django-environ</h3><p>Based on the above, we see that <strong>environment variables are the perfect place to store settings</strong>.</p><p>Now it’s time to talk about the toolkit.</p><p>Writing code using os.environ could be tricky sometimes and require additional effort to handle errors. It’s better to use <a href="https://django-environ.readthedocs.io/en/latest/"><strong>django-environ</strong></a> instead.</p><p>Technically it’s a merge of:</p><ul><li><a href="https://github.com/rconradharris/envparse">envparse</a></li><li><a href="https://github.com/nickstenning/honcho">honcho</a></li><li><a href="https://github.com/kennethreitz/dj-database-url">dj-database-url</a></li><li><a href="https://github.com/dstufft/dj-search-url">dj-search-url</a></li><li><a href="https://github.com/julianwachholz/dj-config-url">dj-config-url</a></li><li><a href="https://github.com/ghickman/django-cache-url">django-cache-url</a></li></ul><p>This app gives a well-functioning API for reading values from environment variables or text files, handful type conversion, etc. Let’s look at some examples.</p><p>settings.py file before:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20803928c96bfb2bf6c7264daebf6699/href">https://medium.com/media/20803928c96bfb2bf6c7264daebf6699/href</a></iframe><p>settings.py file after:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/036ede0a8183ab103313879a82fbe84c/href">https://medium.com/media/036ede0a8183ab103313879a82fbe84c/href</a></iframe><p>.env file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06cbc6feccfe336211cf6f2306ef9ba5/href">https://medium.com/media/06cbc6feccfe336211cf6f2306ef9ba5/href</a></iframe><h3>Setting Structure</h3><p>Instead of splitting settings by environments, you can split them by the source: Django, third- party apps (Celery, DRF, etc.), and your custom settings.</p><p>File structure:</p><pre>project/<br>├── apps/<br>├── settings/<br>│   ├── __init__.py<br>│   ├── djano.py<br>│   ├── project.py<br>│   └── third_party.py<br>└── manage.py</pre><p>__init__.py file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb21d94c5cc7c90c8dfa6b671c422421/href">https://medium.com/media/fb21d94c5cc7c90c8dfa6b671c422421/href</a></iframe><p>Each module could be done as a package, and you can split it more granularly:</p><pre>project/<br>├── apps/<br>├── settings/<br>│   ├── project<br>│   │   ├── __init__.py<br>│   │   ├── custom_module_foo.py<br>│   │   ├── custom_module_bar.py<br>│   │   └── custom_module_xyz.py<br>│   ├── third_party<br>│   │   ├── __init__.py<br>│   │   ├── celery.py<br>│   │   ├── email.py<br>│   │   └── rest_framework.py<br>│   ├── __init__.py<br>│   └── djano.py<br>└── manage.py</pre><h3>Naming Conventions</h3><p>Naming of variables is one of the most complex parts of development. So is naming of settings. We can’t imply on Django or third-party applications, but we can follow these simple rules for our custom (project) settings:</p><ul><li>Give meaningful names to your settings.</li><li>Always use the prefix with the project name for your custom (project) settings.</li><li>Write descriptions for your settings in comments.</li></ul><p><strong>Bad example:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7913df4d8ff53741600d4fc52da0934e/href">https://medium.com/media/7913df4d8ff53741600d4fc52da0934e/href</a></iframe><p><strong>Good example:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5755259407d31183fd9845299005c19e/href">https://medium.com/media/5755259407d31183fd9845299005c19e/href</a></iframe><p>Change MYAWESOMEPROJECT to your real project name.</p><h3>Django Settings: Best practices</h3><ul><li>Keep settings in environment variables.</li><li>Write default values for production configuration (excluding secret keys and tokens).</li><li>Don’t hardcode sensitive settings, and don’t put them in VCS.</li><li>Split settings into groups: Django, third-party, project.</li><li>Follow naming conventions for custom (project) settings.</li></ul><h3>Conclusion</h3><p>The Settings file is a small but very important part of any Django project. If you do it wrong, you’ll have a lot of issues during all phases of development. But if you do it right, it will be a good basis for your project that will allow it to grow and scale in the future.</p><p>Using the environment variables approach, you can easily switch from a monolith to microservice architecture, wrap your project in Docker containers, and deploy it in any VPS or Cloud hosting platform such as Amazon, Google Cloud, or your own Kubernetes cluster.</p><h3>Sources:</h3><ul><li><a href="https://12factor.net/">https://12factor.net/</a></li><li><a href="https://django-environ.readthedocs.io/en/latest/">https://django-environ.readthedocs.io/en/latest/</a></li><li><a href="https://www.twoscoopspress.com/collections/everything/products/two-scoops-of-django-1-11">Two Scopes of Django</a></li></ul><blockquote><em>This article about </em><a href="https://djangostars.com/blog/configuring-django-settings-best-practices/?utm_source=itnext.io&amp;utm_medium=medium&amp;utm_campaign=django%20settings&amp;utm_content=originally%20posted"><strong><em>configuring Django settings</em></strong></a><em> was originally posted on </em><a href="https://djangostars.com/blog/?utm_source=itnext.io&amp;utm_medium=medium&amp;utm_campaign=django%20settings&amp;utm_content=Django%20Stars%20blog"><strong><em>Django Stars blog</em></strong></a><em>.</em></blockquote><figure><a href="https://djangostars.com/services/python-django-development/?utm_source=itnext.io&amp;utm_medium=medium&amp;utm_campaign=django%20settings&amp;utm_content=banner_end"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_uHZvyUk2wIql_cXIsZcw.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85e5e770f54b" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/best-practices-of-configuring-django-settings-85e5e770f54b">Best Practices of Configuring Django Settings</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker tutorial — getting started with Python, Redis, and NGINX]]></title>
            <link>https://medium.com/free-code-camp/docker-tutorial-getting-started-with-python-redis-and-nginx-73ec94ca2f1?source=rss-2a5b28db86e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/73ec94ca2f1</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Alexander Ryabtsev]]></dc:creator>
            <pubDate>Wed, 25 Jul 2018 15:13:09 GMT</pubDate>
            <atom:updated>2019-04-17T16:10:55.327Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RsFzFb8-ghtARn1yP56jzg.png" /></figure><p>This is an <strong>introductory tutorial</strong> on Docker containers. By the end of this article, you will know how to use Docker on your local machine. Along with Python, we are going to run NGINX and Redis containers. These examples assume that you are familiar with the basic concepts of those technologies. There will be lots of shell examples, so go ahead and open the terminal.</p><blockquote><em>Note: the code samples may be displayed improperly because of markdown. I recommend to </em><a href="https://djangostars.com/blog/what-is-docker-and-how-to-use-it-with-python/?utm_source=medium&amp;utm_medium=freecodecamp.org&amp;utm_campaign=docker%20tutorial&amp;utm_content=continue%20reading%20the%20original%20article%20on%20our%20blog"><em>continue reading the original article on our blog</em></a><em> to make sure all the examples are displayed properly.</em></blockquote><h3>What is Docker?</h3><p><a href="https://www.docker.com/"><strong>Docker</strong></a> is an open-source tool that automates the deployment of an application inside a software container. The easiest way to grasp the idea behind Docker is to compare it to, well, standard shipping containers.</p><p>Back in the day, transportation companies faced the following challenges:</p><ul><li>how to transport different, incompatible types of goods side by side. Examples might be like food and chemicals, or glass and bricks.</li><li>how to handle packages of various sizes using the same vehicle.</li></ul><p>After the introduction of containers, bricks could be put over glass, and chemicals could be stored next to food. Cargo of various sizes could be put inside a standardized container and loaded/unloaded by the same vehicle.</p><p>Let’s go back to <strong>containers in </strong><a href="https://djangostars.com/services/python-django-development/?utm_source=medium&amp;utm_medium=freecodecamp.org&amp;utm_campaign=docker%20tutorial&amp;utm_content=software%20development"><strong>software development</strong></a>.</p><figure><a href="https://djangostars.com/services/python-django-development/?utm_source=medium&amp;utm_medium=freecodecamp.org&amp;utm_campaign=docker%20tutorial&amp;utm_content=webdev_banner"><img alt="" src="https://cdn-images-1.medium.com/max/844/1*8iO6FnEiFFGyvnpJinjE5A@2x.png" /></a></figure><p>When you develop an application, you need to provide your code along with all possible dependencies like libraries, the web server, and databases. You may end up in a situation when the application is working on your computer, but won’t even start on the staging server, or the dev, or QA’s machine.</p><p>This challenge can be addressed by isolating the app to make it independent of the system.</p><h3>How does this differ from virtualization?</h3><p>Traditionally, virtual machines (VM) were used to avoid this unexpected behavior. The main problem with VMs is that an “extra OS” on top of the host operating system adds gigabytes of space to the project. Most of the time your server will host several VMs that will take up even more space. And by the way, at the moment, most cloud-based server providers will charge you for that extra space. Another significant drawback of VM is a slow boot.</p><p>Docker eliminates all the above by simply sharing the OS kernel across all the containers running as separate processes of the host OS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xxtakmb4YQjiFWFEx4kzQw.png" /></figure><p>Keep in mind that Docker is not the first or only containerization platform. However, at the moment, Docker is the biggest and the most powerful player on the market.</p><h3>Why do we need Docker?</h3><p>The short list of benefits includes:</p><ul><li>faster development process</li><li>handy application encapsulation</li><li>the same behaviour on local machine / dev / staging / production servers</li><li>easy and clear monitoring</li><li>easy to scale</li></ul><h4>Faster development process</h4><p>There is no need to install 3rd-party apps like PostgreSQL, Redis, or Elasticsearch on the system — you can run them in containers.</p><p>Docker also gives you the ability to run different versions of same application simultaneously. For example, say you need to do some manual data migration from an older version of Postgres to a newer version. You can have such a situation in microservice architecture when you want to create a new microservice with a new version of the 3rd-party software.</p><p>It could be quite complex to keep two different versions of the same app on one host OS. In this case, Docker containers could be a perfect solution — you receive isolated environments for your applications and 3rd-parties.</p><h4>Handy application encapsulation</h4><p>You can deliver your application in one piece. Most programming languages, frameworks, and all operating systems have their own packaging managers. And even if your application can be packed with its native package manager, it could be hard to create a port for another system.</p><p>Docker gives you a unified image format to distribute your applications across different host systems and cloud services. You can deliver your application in one piece with all the required dependencies (included in an image) ready to run.</p><h4>Same behaviour on local machine / dev / staging / production servers</h4><p>Docker can’t guarantee 100% dev / staging / production parity, because there is always the human factor. But it reduces to almost zero the probability of error caused by different versions of operating systems, system-dependencies, and so forth.</p><p>With the right approach to building Docker images, your application will use the same base image with the same OS version and the required dependencies.</p><h4>Easy and clear monitoring</h4><p>Out of the box, you have a unified way to read log files from all running containers. You don’t need to remember all the specific paths where your app and its dependencies store log files, and write custom hooks to handle this. <br>You can integrate an <a href="https://docs.docker.com/config/containers/logging/configure/#supported-logging-drivers">external logging driver</a> and monitor your app log files in one place.</p><h4>Easy to scale</h4><p>A correctly wrapped application will cover most of the <a href="https://12factor.net/">Twelve Factors</a>. By design, Docker forces you follow its core principles, such as configuration over environment variables, and communication over TCP/UDP ports. And if you’ve done your application right, it will be ready for scaling not only in Docker.</p><h3>Supported platforms</h3><p>Docker’s native platform is Linux, as it’s based on features provided by the Linux kernel. However, you can still run it on macOS and Windows. The only difference is that on macOS and Windows, Docker is encapsulated into a tiny virtual machine. At the moment, Docker for macOS and Windows has reached a significant level of usability and feels more like a native app.</p><h3>Installation</h3><p>You can check out the installation instructions for Docker <a href="https://docs.docker.com/install/">here</a>. <br>If you’re running Docker on Linux, you need to run all the following commands as root or add your user to Docker group and re-login:</p><pre>sudo usermod -aG docker $(whoami)</pre><h3>Terminology</h3><ul><li><strong>Container</strong> — a running instance that encapsulates the required software. Containers are always created from images. A container can expose ports and volumes to interact with other containers or/and the outer world. Containers can be easily killed / removed and re-created again in a very short time. Containers don’t keep state.</li><li><strong>Image</strong> — the basic element for every container. When you create an image, every step is cached and can be reused (<a href="https://en.wikipedia.org/wiki/Copy-on-write">Copy On Write model</a>). Depending on the image, it can take some time to build. Containers, on the other hand, can be started from images right away.</li><li><strong>Port</strong> — a TCP/UDP port in its original meaning. To keep things simple, let’s assume that ports can be exposed to the outer world (accessible from the host OS) or connected to other containers — accessible only from those containers and invisible to the outer world.</li><li><strong>Volume</strong> — can be described as a shared folder. Volumes are initialized when a container is created. Volumes are designed to persist data, independent of the container’s lifecycle.</li><li><strong>Registry</strong> — the server that stores Docker images. It can be compared to GitHub — you can pull an image from the registry to deploy it locally, and push locally built images to the registry.</li><li><a href="https://hub.docker.com/explore/"><strong>Docker Hub</strong></a> — a registry with the web interface provided by Docker Inc. It stores a lot of Docker images with different software. Docker Hub is a source of the “official” Docker images made by the Docker team or in cooperation with the original software manufacturer. But it doesn’t necessary mean that these “original” images are from official software manufacturers. Official images list their potential vulnerabilities. This information is available to any logged-in user. There are both free and paid accounts available. You can have one private image per account and an infinite amount of public images for free. Also there is a <a href="https://store.docker.com/search?type=image&amp;source=verified"><strong>Docker Store</strong></a> — a service very similar to Docker Hub. It’s a marketplace with ratings, reviews, and so forth. My personal opinion is that it’s marketing stuff. I’m totally happy with Docker Hub.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z9uWDmkYA7cRhALk.png" /></figure><h3>Example 1: Hello World</h3><p>It’s time to run your first container:</p><pre>docker run ubuntu /bin/echo &#39;Hello world&#39;</pre><p>Console output:</p><pre>Unable to find image &#39;ubuntu:latest&#39; locally  <br>latest: Pulling from library/ubuntu  <br>6b98dfc16071: Pull complete  <br>4001a1209541: Pull complete  <br>6319fc68c576: Pull complete  <br>b24603670dc3: Pull complete  <br>97f170c87c6f: Pull complete  <br>Digest:sha256:5f4bdc3467537cbbe563e80db2c3ec95d548a9145d64453b06939c4592d67b6d  <br>Status: Downloaded newer image for ubuntu:latest  <br>Hello world</pre><ul><li>docker run is a command to run a container.</li><li>ubuntu is the image you run, for example the Ubuntu OS image. When you specify an image, Docker looks first for the image on your Docker host. If the image does not exist locally, then the image is pulled from the public image registry — Docker Hub.</li><li>/bin/echo ‘Hello world’ is the command that will run inside a new container. This container simply prints “Hello world” and stops the execution.</li></ul><p>Let’s try to create an interactive shell inside a Docker container:</p><pre>docker run -i -t --rm ubuntu /bin/bash</pre><ul><li>-t flag assigns a pseudo-tty or terminal inside the new container.</li><li>-i flag allows you to make an interactive connection by grabbing the standard input (STDIN) of the container.</li><li>— rm flag automatically removes the container when the process exits. By default, containers are not deleted. This container exists while we keep the shell session, and terminates when we exit the session (like an SSH session with a remote server).</li></ul><p>If you want to keep the container running after the end of the session, you need to daemonize it:</p><pre>docker run --name daemon -d ubuntu /bin/sh -c &quot;while true; do echo hello world; sleep 1; done&quot;</pre><ul><li>— name daemon assigns a daemon name to a new container. If you don’t specify a name explicitly, Docker will generate and assign it automatically.</li><li>-d flag runs the container in the background (i.e., daemonizes it).</li></ul><p>Let’s see what containers we have at the moment:</p><pre>docker ps -a</pre><p>Console output:</p><pre>CONTAINER ID  IMAGE   COMMAND                 CREATED             STATUS                         PORTS  NAMES  <br>1fc8cee64ec2  ubuntu  &quot;/bin/sh -c &#39;while...&quot;  32 seconds ago      Up 30 seconds                         daemon  <br>c006f1a02edf  ubuntu  &quot;/bin/echo &#39;Hello ...&quot;  About a minute ago  Exited (0) About a minute ago         gifted_nobel</pre><ul><li>docker ps is a command to list containers.</li><li>-a flag shows all containers. Without the -a flag ps will show only running containers.</li></ul><p>The ps shows us that we have two containers:</p><ul><li>gifted_nobel. The name for this container was generated automatically — it will be different on your machine. It’s the first container we created, the one that printed “Hello world” once.</li><li>daemon — the third container we created, which runs as a daemon.</li></ul><p><strong>Note:</strong> there is no second container (the one with interactive shell) because we set the -rm option. As a result, this container is automatically deleted right after execution.</p><p>Let’s check the logs and see what the daemon container is doing right now:</p><pre>docker logs -f daemon</pre><p>Console output:</p><pre>...<br>hello world  <br>hello world  <br>hello world</pre><ul><li>docker logs fetch the logs of a container.</li><li>-f flag to follow the log output (works actually like tail -f).</li></ul><p>Now let’s stop the daemon container:</p><pre>docker stop daemon</pre><p>Make sure the container has stopped.</p><pre>docker ps -a</pre><p>Console output:</p><pre>CONTAINER ID  IMAGE   COMMAND                 CREATED        STATUS                      PORTS  NAMES  <br>1fc8cee64ec2  ubuntu  &quot;/bin/sh -c &#39;while...&quot;  5 minutes ago  Exited (137) 5 seconds ago         daemon  <br>c006f1a02edf  ubuntu  &quot;/bin/echo &#39;Hello ...&quot;  6 minutes ago  Exited (0) 6 minutes ago           gifted_nobel</pre><p>The container is stopped. We can start it again:</p><pre>docker start daemon</pre><p>Let’s ensure that it’s running:</p><pre>docker ps -a</pre><p>Console output:</p><pre>CONTAINER ID  IMAGE   COMMAND                 CREATED        STATUS                    PORTS  NAMES  <br>1fc8cee64ec2  ubuntu  &quot;/bin/sh -c &#39;while...&quot;  5 minutes ago  Up 3 seconds                     daemon  <br>c006f1a02edf  ubuntu  &quot;/bin/echo &#39;Hello ...&quot;  6 minutes ago  Exited (0) 7 minutes ago         gifted_nobel</pre><p>Now, stop it again and remove all the containers manually:</p><pre>docker stop daemon  <br>docker rm &lt;your first container name&gt;  <br>docker rm daemon</pre><p>To remove all containers, we can use the following command:</p><pre>docker rm -f $(docker ps -aq)</pre><ul><li>docker rm is the command to remove the container.</li><li>-f flag (for rm) stops the container if it’s running — a force deletion.</li><li>-q flag (for ps) is to print only container IDs.</li></ul><h3>You May Also Like</h3><ul><li><a href="https://djangostars.com/blog/merging-django-orm-with-sqlalchemy-for-easier-data-analysis/?utm_source=medium&amp;utm_medium=freecodecamp.org&amp;utm_campaign=docker%20tutorial&amp;utm_content=youmayalsolike1">Merging Django ORM with SQLAlchemy for Easier Data Analysis</a></li><li><a href="https://djangostars.com/blog/django-performance-optimization-tips/?utm_source=medium&amp;utm_medium=freecodecamp.org&amp;utm_campaign=docker%20tutorial&amp;utm_content=youmayalsolike2">Django Performance Optimization Tips</a></li></ul><h3>Example 2: Environment variables and volumes</h3><p>Starting from this example, you’ll need several additional files you can find on my <a href="https://github.com/alexryabtsev/docker-workshop/">GitHub repo</a>. You can clone my repo or simply use the <a href="https://github.com/alexryabtsev/docker-workshop/archive/master.zip">following link</a> to download the sample files.</p><p>It’s time to create and run more a meaningful container, like NGINX. <br>Change the directory to examples/nginx:</p><pre>docker run -d --name &quot;test-nginx&quot; -p 8080:80 -v $(pwd):/usr/share/nginx/html:ro nginx:latest</pre><p><strong>Warning:</strong> This command looks quite heavy, but it’s just an example to explain volumes and env variables. In 99% of real-life cases, you won’t start Docker containers manually — you’ll use orchestration services (we’ll cover <a href="https://docs.docker.com/compose/overview/">docker-compose</a> in <a href="https://github.com/alexryabtsev/docker-workshop#example-4-connection-between-containers">example #4</a>) or write a custom script to do it.</p><p>Console output:</p><pre>Unable to find image &#39;nginx:latest&#39; locally  <br>latest: Pulling from library/nginx  <br>683abbb4ea60: Pull complete  <br>a470862432e2: Pull complete  <br>977375e58a31: Pull complete  <br>Digest: sha256:a65beb8c90a08b22a9ff6a219c2f363e16c477b6d610da28fe9cba37c2c3a2ac  <br>Status: Downloaded newer image for nginx:latest  <br>afa095a8b81960241ee92ecb9aa689f78d201cff2469895674cec2c2acdcc61c</pre><ul><li>-p is a ports mapping HOST PORT:CONTAINER PORT.</li><li>-v is a volume mounting HOST DIRECTORY:CONTAINER DIRECTORY.</li></ul><p><strong>Important:</strong> run command accepts only absolute paths. In our example, we’ve used $(pwd) to set the current directory absolute path.</p><p>Now check this <a href="http://127.0.0.1:8080/">URL</a> in your web browser.</p><p>We can try to change /example/nginx/index.html which is mounted as a volume to /usr/share/nginx/html directory inside the container, and refresh the page.</p><p>Let’s get the information about the test-nginx container:</p><pre>docker inspect test-nginx</pre><p>This command displays system-wide information about the Docker installation. This information includes the kernel version, number of containers and images, exposed ports, and mounted volumes.</p><h3>Example 3: Writing your first Dockerfile</h3><p>To build a Docker image, you need to create a Dockerfile. It is a plain text file with instructions and arguments. Here is the description of the instructions we’re going to use in our next example:</p><ul><li>FROM — set base image</li><li>RUN — execute command in container</li><li>ENV — set environment variable</li><li>WORKDIR — set working directory</li><li>VOLUME — create mount-point for a volume</li><li>CMD — set executable for container</li></ul><p>You can check this <a href="https://docs.docker.com/engine/reference/builder/">Dockerfile reference</a> for more details.</p><p>Let’s create an image that will get the contents of the website with curl and store it to the text file. We need to pass the website URL via the environment variable SITE_URL. The resulting file will be placed in a directory, mounted as a volume.</p><p>Place the file name “Dockerfile” in the “examples/curl” directory with the following contents:</p><pre>FROM ubuntu:latest  <br>RUN apt-get update \  <br>    &amp;&amp; apt-get install --no-install-recommends --no-install-suggests -y curl \<br>    &amp;&amp; rm -rf /var/lib/apt/lists/*<br>ENV SITE_URL <a href="http://example.com/">http://example.com/</a>  <br>WORKDIR /data  <br>VOLUME /data  <br>CMD sh -c &quot;curl -Lk $SITE_URL &gt; /data/results&quot;</pre><p>Dockerfile is ready. It’s time to build the actual image.</p><p>Go to the “examples/curl” directory and execute the following command to build an image:</p><pre>docker build . -t test-curl</pre><p>Console output:</p><pre>Sending build context to Docker daemon  3.584kB  <br>Step 1/6 : FROM ubuntu:latest  <br> ---&gt; 113a43faa138<br>Step 2/6 : RUN apt-get update     &amp;&amp; apt-get install --no-install-recommends --no-install-suggests -y curl     &amp;&amp; rm -rf /var/lib/apt/lists/*  <br> ---&gt; Running in ccc047efe3c7<br>Get:1 <a href="http://archive.ubuntu.com/ubuntu">http://archive.ubuntu.com/ubuntu</a> bionic InRelease [242 kB]  <br>Get:2 <a href="http://security.ubuntu.com/ubuntu">http://security.ubuntu.com/ubuntu</a> bionic-security InRelease [83.2 kB]  <br>...<br>Removing intermediate container ccc047efe3c7  <br> ---&gt; 8d10d8dd4e2d<br>Step 3/6 : ENV SITE_URL <a href="http://example.com/">http://example.com/</a>  <br> ---&gt; Running in 7688364ef33f<br>Removing intermediate container 7688364ef33f  <br> ---&gt; c71f04bdf39d<br>Step 4/6 : WORKDIR /data  <br>Removing intermediate container 96b1b6817779  <br> ---&gt; 1ee38cca19a5<br>Step 5/6 : VOLUME /data  <br> ---&gt; Running in ce2c3f68dbbb<br>Removing intermediate container ce2c3f68dbbb  <br> ---&gt; f499e78756be<br>Step 6/6 : CMD sh -c &quot;curl -Lk $SITE_URL &gt; /data/results&quot;  <br> ---&gt; Running in 834589c1ac03<br>Removing intermediate container 834589c1ac03  <br> ---&gt; 4b79e12b5c1d<br>Successfully built 4b79e12b5c1d  <br>Successfully tagged test-curl:latest</pre><ul><li>docker build command builds a new image locally.</li><li>-t flag sets the name tag to an image.</li></ul><p>Now we have the new image, and we can see it in the list of existing images:</p><pre>docker images</pre><p>Console output:</p><pre>REPOSITORY  TAG     IMAGE ID      CREATED         SIZE  <br>test-curl   latest  5ebb2a65d771  37 minutes ago  180 MB  <br>nginx       latest  6b914bbcb89e  7 days ago      182 MB  <br>ubuntu      latest  0ef2e08ed3fa  8 days ago      130 MB</pre><p>We can create and run the container from the image. Let’s try it with the default parameters:</p><pre>docker run --rm -v $(pwd)/vol:/data/:rw test-curl</pre><p>To see the results saved to file, run:</p><pre>cat ./vol/results</pre><p>Let’s try with <a href="http://facebook.com/">Facebook.com</a>:</p><pre>docker run --rm -e SITE_URL=<a href="https://facebook.com/">https://facebook.com/</a> -v $(pwd)/vol:/data/:rw test-curl</pre><p>To see the results saved to file, run:</p><pre>cat ./vol/results</pre><h4>Best practices for creating images</h4><ul><li>Include only <strong>necessary context</strong> — use a <a href="https://docs.docker.com/engine/reference/builder/#dockerignore-file">.dockerignore</a> file (like .gitignore in git)</li><li>Avoid installing <strong>unnecessary packages</strong> — it will consume extra disk space.</li><li><strong>Use cache</strong>. Add context that changes a lot, for example, the source code of your project, at the end of Dockerfile — it will utilize Docker cache effectively.</li><li><strong>Be careful with volumes</strong>. You should remember what data is in volumes. Because volumes are persistent and don’t die with the containers, the next container will use data from the volume created by the previous container.</li><li><strong>Use </strong><a href="https://docs.docker.com/engine/reference/builder/#environment-replacement"><strong>environment variables</strong></a> in RUN, EXPOSE, VOLUME. It will make your Dockerfile more flexible.</li></ul><h4>Alpine images</h4><p>A lot of Docker images (versions of images) are created on top of <a href="https://alpinelinux.org/"><strong>Alpine Linux</strong></a> — this is a lightweight distro that allows you to reduce the overall size of Docker images.</p><p>I recommend that you use images based on Alpine for third-party services, such as Redis and Postgres. For your app images, use images based on <a href="https://hub.docker.com/_/buildpack-deps/"><strong>buildpack</strong></a>. It will be easy to debug inside the container, and you’ll have a lot of pre-installed system-wide requirements.</p><p>Only you can decide which base image to use. You can get maximum benefit by using one basic image for all images — in this case, the cache will be used more effectively.</p><h3>Example 4: Connection between containers</h3><p><a href="https://docs.docker.com/compose/overview/"><strong>Docker Compose</strong></a><strong> </strong>is a CLI utility used to connect containers with each other. You can install Docker Compose <a href="https://pypi.org/project/docker-compose/">via </a><a href="https://pypi.org/project/docker-compose/">pip</a>:</p><pre>sudo pip install docker-compose</pre><p>In this example, I am going to connect Python and Redis containers.</p><pre>version: &#39;3.6&#39;  <br>services:  <br>  app:<br>    build:<br>      context: ./app<br>    depends_on:<br>      - redis<br>    environment:<br>      - REDIS_HOST=redis<br>    ports:<br>      - &quot;5000:5000&quot;<br>  redis:<br>    image: redis:3.2-alpine<br>    volumes:<br>      - redis_data:/data<br>volumes:  <br>  redis_data:</pre><p>Go to “examples/compose” and execute the following command:</p><pre>docker-compose up</pre><p>Console output:</p><pre>Building app  <br>Step 1/9 : FROM python:3.6.3  <br>3.6.3: Pulling from library/python  <br>f49cf87b52c1: Pull complete  <br>7b491c575b06: Pull complete  <br>b313b08bab3b: Pull complete  <br>51d6678c3f0e: Pull complete  <br>09f35bd58db2: Pull complete  <br>1bda3d37eead: Pull complete  <br>9f47966d4de2: Pull complete  <br>9fd775bfe531: Pull complete  <br>Digest: sha256:cdef88d8625cf50ca705b7abfe99e8eb33b889652a9389b017eb46a6d2f1aaf3  <br>Status: Downloaded newer image for python:3.6.3  <br> ---&gt; a8f7167de312<br>Step 2/9 : ENV BIND_PORT 5000  <br> ---&gt; Running in 3b6fe5ca226d<br>Removing intermediate container 3b6fe5ca226d  <br> ---&gt; 0b84340fa920<br>Step 3/9 : ENV REDIS_HOST localhost  <br> ---&gt; Running in a4f9a1d6f541<br>Removing intermediate container a4f9a1d6f541  <br> ---&gt; ebe63bf5959e<br>Step 4/9 : ENV REDIS_PORT 6379  <br> ---&gt; Running in fd06aa65fd33<br>Removing intermediate container fd06aa65fd33  <br> ---&gt; 2a581c31ff4f<br>Step 5/9 : COPY ./requirements.txt /requirements.txt  <br> ---&gt; 671093a12829<br>Step 6/9 : RUN pip install -r /requirements.txt  <br> ---&gt; Running in b8ea53bc6ba6<br>Collecting flask==1.0.2 (from -r /requirements.txt (line 1))  <br>  Downloading <a href="https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl">https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl</a> (91kB)<br>Collecting redis==2.10.6 (from -r /requirements.txt (line 2))  <br>  Downloading <a href="https://files.pythonhosted.org/packages/3b/f6/7a76333cf0b9251ecf49efff635015171843d9b977e4ffcf59f9c4428052/redis-2.10.6-py2.py3-none-any.whl">https://files.pythonhosted.org/packages/3b/f6/7a76333cf0b9251ecf49efff635015171843d9b977e4ffcf59f9c4428052/redis-2.10.6-py2.py3-none-any.whl</a> (64kB)<br>Collecting click&gt;=5.1 (from flask==1.0.2-&gt;-r /requirements.txt (line 1))  <br>  Downloading <a href="https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl">https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl</a> (71kB)<br>Collecting Jinja2&gt;=2.10 (from flask==1.0.2-&gt;-r /requirements.txt (line 1))  <br>  Downloading <a href="https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl">https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl</a> (126kB)<br>Collecting itsdangerous&gt;=0.24 (from flask==1.0.2-&gt;-r /requirements.txt (line 1))  <br>  Downloading <a href="https://files.pythonhosted.org/packages/dc/b4/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4/itsdangerous-0.24.tar.gz">https://files.pythonhosted.org/packages/dc/b4/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4/itsdangerous-0.24.tar.gz</a> (46kB)<br>Collecting Werkzeug&gt;=0.14 (from flask==1.0.2-&gt;-r /requirements.txt (line 1))  <br>  Downloading <a href="https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl">https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl</a> (322kB)<br>Collecting MarkupSafe&gt;=0.23 (from Jinja2&gt;=2.10-&gt;flask==1.0.2-&gt;-r /requirements.txt (line 1))  <br>  Downloading <a href="https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz">https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz</a><br>Building wheels for collected packages: itsdangerous, MarkupSafe  <br>  Running setup.py bdist_wheel for itsdangerous: started<br>  Running setup.py bdist_wheel for itsdangerous: finished with status &#39;done&#39;<br>  Stored in directory: /root/.cache/pip/wheels/2c/4a/61/5599631c1554768c6290b08c02c72d7317910374ca602ff1e5<br>  Running setup.py bdist_wheel for MarkupSafe: started<br>  Running setup.py bdist_wheel for MarkupSafe: finished with status &#39;done&#39;<br>  Stored in directory: /root/.cache/pip/wheels/33/56/20/ebe49a5c612fffe1c5a632146b16596f9e64676768661e4e46<br>Successfully built itsdangerous MarkupSafe  <br>Installing collected packages: click, MarkupSafe, Jinja2, itsdangerous, Werkzeug, flask, redis  <br>Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-1.0.2 itsdangerous-0.24 redis-2.10.6  <br>You are using pip version 9.0.1, however version 10.0.1 is available.  <br>You should consider upgrading via the &#39;pip install --upgrade pip&#39; command.  <br>Removing intermediate container b8ea53bc6ba6  <br> ---&gt; 3117d3927951<br>Step 7/9 : COPY ./app.py /app.py  <br> ---&gt; 84a82fa91773<br>Step 8/9 : EXPOSE $BIND_PORT  <br> ---&gt; Running in 8e259617b7b5<br>Removing intermediate container 8e259617b7b5  <br> ---&gt; 55f447f498dd<br>Step 9/9 : CMD [ &quot;python&quot;, &quot;/app.py&quot; ]  <br> ---&gt; Running in 2ade293ecb25<br>Removing intermediate container 2ade293ecb25  <br> ---&gt; b85b4246e9f8</pre><pre>Successfully built b85b4246e9f8  <br>Successfully tagged compose_app:latest  <br>WARNING: Image for service app was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.  <br>Creating compose_redis_1 ... done  <br>Creating compose_app_1   ... done  <br>Attaching to compose_redis_1, compose_app_1  <br>redis_1  | 1:C 08 Jul 18:12:21.851 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf  <br>redis_1  |                 _._  <br>redis_1  |            _.-``__ &#39;&#39;-._  <br>redis_1  |       _.-``    `.  `_.  &#39;&#39;-._           Redis 3.2.12 (00000000/0) 64 bit  <br>redis_1  |   .-`` .-```.  ```\/    _.,_ &#39;&#39;-._  <br>redis_1  |  (    &#39;      ,       .-`  | `,    )     Running in standalone mode  <br>redis_1  |  |`-._`-...-` __...-.``-._|&#39;` _.-&#39;|     Port: 6379  <br>redis_1  |  |    `-._   `._    /     _.-&#39;    |     PID: 1  <br>redis_1  |   `-._    `-._  `-./  _.-&#39;    _.-&#39;  <br>redis_1  |  |`-._`-._    `-.__.-&#39;    _.-&#39;_.-&#39;|  <br>redis_1  |  |    `-._`-._        _.-&#39;_.-&#39;    |           <a href="http://redis.io/">http://redis.io</a>  <br>redis_1  |   `-._    `-._`-.__.-&#39;_.-&#39;    _.-&#39;  <br>redis_1  |  |`-._`-._    `-.__.-&#39;    _.-&#39;_.-&#39;|  <br>redis_1  |  |    `-._`-._        _.-&#39;_.-&#39;    |  <br>redis_1  |   `-._    `-._`-.__.-&#39;_.-&#39;    _.-&#39;  <br>redis_1  |       `-._    `-.__.-&#39;    _.-&#39;  <br>redis_1  |           `-._        _.-&#39;  <br>redis_1  |               `-.__.-&#39;  <br>redis_1  |  <br>redis_1  | 1:M 08 Jul 18:12:21.852 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.  <br>redis_1  | 1:M 08 Jul 18:12:21.852 # Server started, Redis version 3.2.12  <br>redis_1  | 1:M 08 Jul 18:12:21.852 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add &#39;vm.overcommit_memory = 1&#39; to /etc/sysctl.conf and then reboot or run the command &#39;sysctl vm.overcommit_memory=1&#39; for this to take effect.  <br>redis_1  | 1:M 08 Jul 18:12:21.852 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command &#39;echo never &gt; /sys/kernel/mm/transparent_hugepage/enabled&#39; as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.  <br>redis_1  | 1:M 08 Jul 18:12:21.852 * The server is now ready to accept connections on port 6379  <br>app_1    |  * Serving Flask app &quot;app&quot; (lazy loading)  <br>app_1    |  * Environment: production  <br>app_1    |    WARNING: Do not use the development server in a production environment.  <br>app_1    |    Use a production WSGI server instead.  <br>app_1    |  * Debug mode: on  <br>app_1    |  * Running on <a href="http://0.0.0.0:5000/">http://0.0.0.0:5000/</a> (Press CTRL+C to quit)  <br>app_1    |  * Restarting with stat  <br>app_1    |  * Debugger is active!  <br>app_1    |  * Debugger PIN: 170-528-240</pre><p>The current example will increment the view counter in Redis. Open the <a href="http://127.0.0.1:5000/">following URL</a> in your web browser and check it.</p><p>How to use Docker Compose is a topic for a separate tutorial. To get started, you can play with some images from Docker Hub. If you want to create your own images, follow the best practices listed above.</p><p>The only thing I can add in terms of using Docker Compose is that you should always <strong>give explicit names to your volumes</strong> in“ docker-compose.yml” (if the image has volumes). This simple rule will save you from an issue in the future when you’re inspecting your volumes.</p><pre>version: &#39;3.6&#39;  <br>services:  <br>  ...<br>  redis:<br>    image: redis:3.2-alpine<br>    volumes:<br>      - redis_data:/data<br>volumes:  <br>  redis_data:</pre><p>In this case, redis_data will be the name inside the “docker-compose.yml” file. For the real volume name, it will be prepended with project name prefix.</p><p>To see volumes, run:</p><pre>docker volume ls</pre><p>Console output:</p><pre>DRIVER              VOLUME NAME  <br>local               apptest_redis_data</pre><p>Without an explicit volume name, there will be a UUID. Here’s an example from my local machine:</p><pre>DRIVER              VOLUME NAME  <br>local               ec1a5ac0a2106963c2129151b27cb032ea5bb7c4bd6fe94d9dd22d3e72b2a41b  <br>local               f3a664ce353ba24dd43d8f104871594de6024ed847054422bbdd362c5033fc4c  <br>local               f81a397776458e62022610f38a1bfe50dd388628e2badc3d3a2553bb08a5467f  <br>local               f84228acbf9c5c06da7be2197db37f2e3da34b7e8277942b10900f77f78c9e64  <br>local               f9958475a011982b4dc8d8d8209899474ea4ec2c27f68d1a430c94bcc1eb0227  <br>local               ff14e0e20d70aa57e62db0b813db08577703ff1405b2a90ec88f48eb4cdc7c19  <br>local               polls_pg_data  <br>local               polls_public_files  <br>local               polls_redis_data  <br>local               projectdev_pg_data  <br>local               projectdev_redis_data</pre><h3>Docker way</h3><p>Docker has some restrictions and requirements, depending on the architecture of your system (applications that you pack into containers). You can ignore these requirements or find some workarounds — but you won’t get all the benefits of using Docker. My strong advice is to follow these recommendations:</p><ul><li><strong>1 application = 1 container</strong>.</li><li>Run the process in the <strong>foreground.</strong> Don’t use systemd, upstart, or any other similar tools.</li><li><strong>Keep data out of containers</strong> — use volumes.</li><li><strong>Do not use SSH.</strong> If you need to step into a container, you can use the docker exec command.</li><li><strong>Avoid manual configurations</strong> or actions inside containers.</li></ul><h3>Conclusion</h3><p>To summarize this tutorial, alongside with IDE and Git, Docker has become a must-have developer tool. It’s a production-ready tool with a rich and mature infrastructure.</p><p>Docker can be used on all types of projects, regardless of size and complexity. In the beginning, you can start with <a href="https://docs.docker.com/compose/overview/">Compose</a> and <a href="https://docs.docker.com/engine/swarm/">Swarm</a>. When the project grows, you can migrate to cloud services like <a href="https://aws.amazon.com/containers/">Amazon Container Services</a> or <a href="https://kubernetes.io/">Kubernetes</a>.</p><p>Like standard containers used in cargo transportation, wrapping your code in Docker containers will help you build faster and more efficient CI/CD processes. This is not just another technological trend promoted by a bunch of geeks — it’s a new paradigm that is already being used in the architecture of large companies like <a href="https://blog.docker.com/2017/12/containers-at-paypal/">PayPal</a>, <a href="https://blog.docker.com/2017/04/visa-inc-gains-speed-operational-efficiency-docker-enterprise-edition/">Visa</a>, <a href="https://www.docker.com/customers/swisscom-goes-400vms-20vms-docker">Swisscom</a>, <a href="https://www.docker.com/customers/ge-uses-docker-enable-self-service-their-developers">General Electric</a>, <a href="https://www.docker.com/customers/docker-datacenter-delivers-splunks-house-demos">Splink</a>, and more.</p><p>You are always welcome to ask questions and share topics you want to read about!</p><p><strong>Have you already used Docker on your project? Leave me a comment or ask questions below!</strong></p><figure><a href="https://djangostars.com/services/python-django-development/?utm_source=medium&amp;utm_medium=freecodecamp.org&amp;utm_campaign=docker%20tutorial&amp;utm_content=banner_end"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DdZ7gDbH7I9rnq7Z2xauiA.png" /></a></figure><blockquote>This article about<a href="https://djangostars.com/blog/what-is-docker-and-how-to-use-it-with-python/?utm_source=medium&amp;utm_medium=freecodecamp.org&amp;utm_campaign=docker%20tutorial&amp;utm_content=docker"> <strong>Docker</strong></a><strong> </strong>is originally published on <strong>Django Stars blog</strong>.</blockquote><blockquote><em>If you find this post useful, please tap 👏 button below :)</em></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F833939-2%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F833939-2%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/23806bfe1f184df6c93c60e10e7fdc04/href">https://medium.com/media/23806bfe1f184df6c93c60e10e7fdc04/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73ec94ca2f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/docker-tutorial-getting-started-with-python-redis-and-nginx-73ec94ca2f1">Docker tutorial — getting started with Python, Redis, and NGINX</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>