GithubHelp home page GithubHelp logo

Comments (10)

Arturomtz8 avatar Arturomtz8 commented on June 19, 2024 1

Hello, I finally knew why the volume wasn't working, the problem is the path inside the container, because in the book says that you must mount the volume like so:
-v newsbot-data:/data

But the correct path to save the newsbot.db of the container is:
/apps/subredditfetcher/data

I figured it out entering to bash and navigating to the data folder where the db is stored and using pwd.
So the correct way to ensure that data is persisted is:
-v newsbot-data:/apps/subredditfetcher/data

The full command would be:
docker run -d --rm --name reddit-bot -e NBT_ACCESS_TOKEN -v newsbot-data:/apps/subredditfetcher/data reddit-image

from practical-docker-with-python.

SathyaBhat avatar SathyaBhat commented on June 19, 2024

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.

can you post what commands are you running when you:

  • first start the container
  • stop & start the container?

from practical-docker-with-python.

Arturomtz8 avatar Arturomtz8 commented on June 19, 2024

Sure.
Command for building the image:
docker build -t sathyabhat/newsbot-sqlite .
Command for starting the container:
docker run --rm --name newsbot-sqlite -e NBT_ACCESS_TOKEN -v newsbot-data:/data sathyabhat/newsbot-sqlite
Stop the container:
Control + C
Re-run the container:
docker run --rm --name newsbot-sqlite -e NBT_ACCESS_TOKEN -v newsbot-data:/data sathyabhat/newsbot-sqlite
Thanks a lot.

from practical-docker-with-python.

SathyaBhat avatar SathyaBhat commented on June 19, 2024

I can't see to repro this error:

Built the container, and ran it as you said:

docker run --rm --name newsbot-sqlite -e NBT_ACCESS_TOKEN -v newsbot-data:/data sathyabhat/newsbot-sqlite

INFO: 2022-08-08 00:03:29,167 - <module> - Starting newsbot
INFO: 2022-08-08 00:03:31,090 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:03:35,875 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:03:37,662 - get_updates - received response: {'ok': True, 'result': []}
...
INFO: 2022-08-08 00:03:55,998 - handle_incoming_messages - Chat text received: /source docker
INFO: 2022-08-08 00:03:55,998 - handle_incoming_messages - Sources set for 7342383 to  docker
INFO: 2022-08-08 00:03:55,999 - handle_incoming_messages - Updated 1 rows
INFO: 2022-08-08 00:03:58,620 - get_updates - received response: {'ok': True, 'result': []}
^CINFO: 2022-08-08 00:04:02,206 - <module> - Received KeybInterrupt, exiting

Ctrl+C & start again

INFO: 2022-08-08 00:04:17,490 - <module> - Starting newsbot
INFO: 2022-08-08 00:04:19,304 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:04:24,090 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:04:25,874 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:04:28,962 - get_latest_news - Fetching subreddits: {sub_reddits}

image

It does fetch.

Comma separated subreddits work as well:

INFO: 2022-08-08 00:05:05,305 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:05:07,088 - handle_incoming_messages - Chat text received: /source docker, kubernetes
INFO: 2022-08-08 00:05:07,088 - handle_incoming_messages - Sources set for 7342383 to  docker, kubernetes
INFO: 2022-08-08 00:05:07,089 - handle_incoming_messages - Updated 1 rows
INFO: 2022-08-08 00:05:09,689 - get_updates - received response: {'ok': True, 'result': []}
INFO: 2022-08-08 00:05:14,481 - get_updates - received response: {'ok': True, 'result': []}
...
INFO: 2022-08-08 00:05:16,265 - handle_incoming_messages - Chat text received: /fetch
INFO: 2022-08-08 00:05:17,073 - get_latest_news - Fetching subreddits: {sub_reddits}

You can see it works:

image

Are the subreddits private or quarantined? It might not work if that's the case, but I am happy to test out if you mention them.

For the SQLite, maybe the volume is shared with a previous run? Can you try with a fresh volume by removing the existing one

docker volume rm newsbot-data

And then trying again?

from practical-docker-with-python.

SathyaBhat avatar SathyaBhat commented on June 19, 2024

fwiw I added a commit to fix the subreddit lists not showing right 04410b6

from practical-docker-with-python.

Arturomtz8 avatar Arturomtz8 commented on June 19, 2024

I tried removing the volume but nope, it still doesn't recognizes my sources set before when re-running the container. Nevertheless I could accomplish to assign more than one subreddit in the sources. The data persistency still is very strange because Im using the same code of the repo, and when recreating the environment and trying to fetch the news:
Screen Shot 2022-08-12 at 9 42 21

from practical-docker-with-python.

Arturomtz8 avatar Arturomtz8 commented on June 19, 2024

I inspected the sqlite db using DBeaver, and it is not saving anything there. That should be the reason

from practical-docker-with-python.

SathyaBhat avatar SathyaBhat commented on June 19, 2024

I inspected the sqlite db using DBeaver, and it is not saving anything there. That should be the reason

How did you examine the sqlite DB?

from practical-docker-with-python.

Arturomtz8 avatar Arturomtz8 commented on June 19, 2024

using db beaver, you select the path to the database and connect, then you can make queries, and it didn't contain my sources even I restarted the container.

from practical-docker-with-python.

SathyaBhat avatar SathyaBhat commented on June 19, 2024

I meant to ask how are you getting the location of the db. Are you doing a docker volume inspect on the database to determine the location?

Can you try using a bind mount and see that the data gets saved?

docker run --rm --name newsbot-sqlite -e NBT_ACCESS_TOKEN -v $HOME/newsbot-data:/data sathyabhat/newsbot-sqlite

from practical-docker-with-python.

Related Issues (11)

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.