Giter VIP home page Giter VIP logo

practical-docker-with-python's Introduction

Apress Source Code

This repository accompanies Practical Docker with Python first and second editions by Sathyajith Bhat (Apress, 2018 & 2022).

first edition cover image second edition cover

Download the files as a zip using the green button, or clone the repository to your machine using Git.

The source code is available chapter wise and is available in /source-code directory. The zip files referenced in each chapter is available under releases corresponding to each filename referenced in the exercise. The structure is as below

── chapter-3
│   ├── python-app
── chapter-4
│   ├── exercise-1
│   │   ├── docker-hello-world
│   ├── exercise-2
│   │   ├── docker-multi-stage
│   └── exercise-3
│       └── newsbot
├── chapter-5
│   ├── exercise-1
│   │   ├── docker-volume-bind-mount
│   └── exercise-2
│       ├── docker-subreddit-fetcher-volume
├── chapter-6
│   └── exercise-1
│       ├── docker-subreddit-fetcher-network
└── chapter-7
    ├── exercise-1
    │   └── docker-compose-adminer
    └── exercise-2
        └── subreddit-fetcher-compose

Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

v2.0

  • Updates to cover the second edition

v1.1

  • Some fixes to clean up the code structure and correct bugs as reported

Contributions

See the file Contributing.md for more information on how you can contribute to this repository.

practical-docker-with-python's People

Contributors

akozyreva avatar dependabot[bot] avatar markp88 avatar sathyabhat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

practical-docker-with-python's Issues

missing documentation in the book

Hi,

I am reading the electronic version of your book on Scribd, so maybe that's abridged and my notes don't apply to the paper version. Just in case they do,

  1. I saw no mention of this repo in the text. So when I read on p.46 pip3 install -r requirements.txt I was wondering which requirements.txt file you were referring to. I went to the APress site on a hunch and found the link to the downloads there.
  2. Just following along, once I had the bot set up and issued the first /fetch order, the bot threw an error message because I didn't have a Reddit Client ID or Client Secret (see screenshot)
    Screenshot 2020-04-26 at 3 25 24 PM

The error message is fortunately descriptive, so I was able to generate those. But that step could have been documented.

Other than that, I really enjoy the book.

Thanks,
Matt

ClientException

Following the instructions, when fetching the news:

NBT_ACCESS_TOKEN=<token> python newsbot.py

within the docker subreddit fetcher directory, I receive the following error:

INFO: 2018-09-03 17:49:10,101 - post_message - posting Hang on, fetching your news.. to 25359320
Traceback (most recent call last):
  File "newsbot.py", line 24, in <module>
    handle_incoming_messages(States.last_updated)
  File "/Users/gu/Workspace/telegram_bots/practical-docker-with-python/docker subreddit fetcher/telegram.py", line 85, in handle_incoming_messages
    summarized_news = get_latest_news(sources_dict[person_id])
  File "/Users/gu/Workspace/telegram_bots/practical-docker-with-python/docker subreddit fetcher/reddit.py", line 14, in get_latest_news
    r = praw.Reddit(user_agent='Telegram Xiled Chippians Group')
  File "/Users/gu/Workspace/telegram_bots/practical-docker-with-python/venv/lib/python3.7/site-packages/praw/reddit.py", line 150, in __init__
    raise ClientException(required_message.format(attribute))
praw.exceptions.ClientException: Required configuration setting 'client_id' missing. 
This setting can be provided in a praw.ini file, as a keyword argument to the `Reddit` class constructor, or as an environment variable.

Shouldn't the bot authenticate against the Reddit API?

AttributeError: 'Reddit' object has no attribute 'get_subreddit'

I'm seeing an AttributeError when running on python3.6 or 3.7 currently:

Traceback (most recent call last):
  File "newsbot.py", line 24, in <module>
    handle_incoming_messages(States.last_updated)
  File "/Users/spencer.anderson/testing/pythonshenanigans/tgramred/docker_subred_fetch/telegram.py", line 85, in handle_incoming_messages
    summarized_news = get_latest_news(sources_dict[person_id])
  File "/Users/spencer.anderson/testing/pythonshenanigans/tgramred/docker_subred_fetch/reddit.py", line 29, in get_latest_news
    submissions = r.get_subreddit(sub_reddits).get_top(limit=5)
AttributeError: 'Reddit' object has no attribute 'get_subreddit'

I made the call this, however this will likely only work with 1 subreddit and not multiple.
submissions = r.subreddit(sub_reddits).top(limit=5)

It was submissions = r.get_subreddit(sub_reddits).get_top(limit=5)

Getting exception while running chapter-3 module

Not able to connect to reddit. If you have sen this issue before

raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.reddit.com', port=443): 

Max retries exceeded with url: /r/test/top.json?limit=5 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

exercise 1 of chapter 6

In this part, the dockerfile didn't point out the a specific Python3 version and build the image with newest python3 version by default ,which cause some problems.
For example , for python 3.10, some old features were removed.

["Awaitable", "Coroutine", "AsyncIterable", "AsyncIterator", "AsyncGenerator", "Hashable", "Iterable", "Iterator", "Generator", "Reversible", "Sized", "Container", "Callable", "Collection", "Set", "MutableSet", "Mapping", "MutableMapping", "MappingView", "KeysView", "ItemsView", "ValuesView", "Sequence", "MutableSequence", "ByteString"]

if we build the target docker image with the dockfile in sourcecode, we will capture some bugs

Collecting peewee==3.0.4
  Downloading peewee-3.0.4.tar.gz (592 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 592.1/592.1 kB 2.7 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [11 lines of output]
      /tmp/pip-install-mjill3ii/peewee_8a9f4baa9bdb444c9f5b97bab68d2996/setup.py:22: UserWarning: Cython C extensions for peewee will NOT be built, because Cython does not seem to be installed. To enable Cython C extensions, install Cython >=0.22.1.
        warnings.warn('Cython C extensions for peewee will NOT be built, because '
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-mjill3ii/peewee_8a9f4baa9bdb444c9f5b97bab68d2996/setup.py", line 66, in <module>
          version=__import__('peewee').__version__,
                  ^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-install-mjill3ii/peewee_8a9f4baa9bdb444c9f5b97bab68d2996/peewee.py", line 157, in <module>
          from collections import Callable
      ImportError: cannot import name 'Callable' from 'collections' (/usr/local/lib/python3.11/collections/__init__.py)
      [end of output]

we can see it uses the python3.11 by default.
After replacing python3 with python 3.11, I solved the problem

So, I think it's better to point out a specific python3 version in your dockerfiles.
like python 3.7
FROM python:3.7-alpine

Exercise 2 of chapter 5

The data persistency doesn't work with the sqlite db, I followed the steps as the book said and didn't change anything of the code. When I stop de container and run it again, it doesn't recognize my subreddit source. Also it doesn't allow put a list of subreddits as sources, it only takes the last one.

No Output

I am at the end of chapter 4 when I try to run docker run --name subreddit_fetcher_bot sathyabhat:subreddit_fetcher, I see no output.

I am using files in this directory. Nothing is modified except the token in the Dockerfile

When I try to run the application after creating virtualenv (without dockerizing it) I get this error:

(env) x@x-desktop:~/tmp/docker subreddit fetcher$ BOT_KEY=my_token python newsbot.py 
Traceback (most recent call last):
  File "newsbot.py", line 24, in <module>
    handle_incoming_messages(States.last_updated)
  File "/home/x/tmp/docker subreddit fetcher/telegram.py", line 37, in handle_incoming_messages
    r = get_updates(last_updated)
  File "/home/x/tmp/docker subreddit fetcher/telegram.py", line 15, in get_updates
    response = requests.get(API_BASE + BOT_KEY + '/getUpdates', params={'offset': last_updated+1})
TypeError: must be str, not NoneType
(env) x@x-desktop:~/tmp/docker subreddit fetcher$ 

Alpine doesn't reinstall cached files, it can't install pandas

In the content A LOOK AT SLIM DOCKER RELEASE IMAGE (USING MULTI-STAGE BUILDS)
Dockerfile Listing

FROM python:3 as python-base
COPY requirements.txt .
RUN pip install -r requirements.txt
FROM python:3-alpine
COPY --from=python-base /root/.cache /root/.cache
Chapter 4 Understanding the doCkerfile87
COPY --from=python-base requirements.txt .
RUN pip install -r requirements.txt && rm -rf /root/.cache

copy the files installed from the first stage, reinstall
them (notice this time, pip fetches the cached files and doesn’t build them
again), and then delete the cached install files.

I have pandas and numpy within my dependencies.
When I build the dockerfile it will not install pandas from /root/.cache. And it even can't install pandas from bash within the container.

Chapter 5 excercise 2 error

Getting the below error when trying to build the dockerfile in chapter 5 ex 2:

[5/5] RUN pip install -r requirements.txt:
#8 4.700 Collecting peewee==2.10.2
#8 4.940 Downloading peewee-2.10.2.tar.gz (516 kB)
#8 5.008 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 516.1/516.1 KB 9.7 MB/s eta 0:00:00
#8 5.103 Preparing metadata (setup.py): started
#8 5.879 Preparing metadata (setup.py): finished with status 'error'
#8 5.906 error: subprocess-exited-with-error
#8 5.906
#8 5.906 × python setup.py egg_info did not run successfully.
#8 5.906 │ exit code: 1
#8 5.906 ╰─> [10 lines of output]
#8 5.906 /tmp/pip-install-bhpn8q8f/peewee_5353c5985ec14e7f815c7fe81f7e544d/setup.py:21: UserWarning: Cython C extensions for peewee will NOT be built, because Cython does not seem to be installed. To enable Cython C extensions, install Cython >=0.22.1.
#8 5.906 warnings.warn('Cython C extensions for peewee will NOT be built, because '
#8 5.906 Traceback (most recent call last):
#8 5.906 File "", line 2, in
#8 5.906 File "", line 34, in
#8 5.906 File "/tmp/pip-install-bhpn8q8f/peewee_5353c5985ec14e7f815c7fe81f7e544d/setup.py", line 64, in
#8 5.906 version=import('peewee').version,
#8 5.906 File "/tmp/pip-install-bhpn8q8f/peewee_5353c5985ec14e7f815c7fe81f7e544d/peewee.py", line 124, in
#8 5.906 from collections import Callable
#8 5.906 ImportError: cannot import name 'Callable' from 'collections' (/usr/local/lib/python3.10/collections/init.py)
#8 5.906 [end of output]
#8 5.906
#8 5.906 note: This error originates from a subprocess, and is likely not a problem with pip.
#8 5.909 error: metadata-generation-failed
#8 5.909
#8 5.909 × Encountered error while generating package metadata.
#8 5.909 ╰─> See above for output.
#8 5.909
#8 5.909 note: This is an issue with the package mentioned above, not pip.
#8 5.909 hint: See above for details.
#8 6.162 WARNING: You are using pip version 22.0.4; however, version 22.1.1 is available.
#8 6.162 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

Same error occurs if I add a line 'RUN ["pip", "install", "--upgrade", "pip"]' to the dockerfile and if I add Cython=0.22.1 to requirements.txt

Also note that this version of the file differs significantly from the version in the book, but is erroring out on the requirements install line which is no different between this repo + the book version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.