A
A
Alex Fedorov2021-06-28 16:26:51
Python
Alex Fedorov, 2021-06-28 16:26:51

Running postgres server on docker?

There is a table with one column called ID, there will be located the IDs of the users who will run the ID.
And there is a trigger word kuku which shows all the id's in the table.

Code itself:

from aiogram import Bot, Dispatcher, executor
from aiogram.types import Message
import logging
import psycopg2
from aiogram.dispatcher.filters.builtin import CommandStart, Text

bot = Bot(token = 'SECRET')
dp = Dispatcher(bot)
logging .basicConfig(format=u'%(filename)s [LINE:%(lineno)d] #%(levelname)-8s [%(asctime)s] %(message)s',
level=logging.INFO)

@dp .message_handler(CommandStart())
async def welcome(message: Message):
user_id = message.chat.id
conn = psycopg2.connect(dbname = "postgres",
user = "postgres",
password = "oybek123",
host = "localhost",
port = 5432)
cursor = conn.cursor()
cursor. execute("INSERT INTO id_list(id) VALUES(%s)",(user_id,))
conn.commit()
conn.close()

@dp.message_handler(Text(equals=["kuku"]))
async def feedback_press_button (message: Message):
conn = psycopg2.connect(dbname="postgres",
user="postgres",
password="oybek123",
host="localhost",
port=5432)
cursor = conn.cursor()
cursor.execute("SELECT * FROM id_list")
grab_data = cursor.fetchall()
for val in grab_data:
await message.answer(val[0])
conn.commit()
conn.close()

await message.answer("OK")

if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)

============= =================

CODE is not perfect, I will fix it.. But I would like to learn how to do the following. Run BOTA+DATABASE on docker.
Just like an experiment. I want to learn something new.

Here is the dockerfile:

FROM python:3.9

RUN mkdir /src
WORKDIR /src
COPY . /src
RUN pip install -r requirements.txt

docker-compose:

version: '3.1'

services:
tgbot:
container_name: bot
build:
context: .
command: python main.py
restart: always
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example

adminer:
image: adminer
restart: always
ports:
- 8080:8080
============== ================================================

1 ) the settings of the tgbot service, in my opinion, are correct, and the bot itself starts.

2) ADMINER:

there is an admin panel for the admin database, it starts at the address that I set here

conn = psycopg2.connect(dbname = "postgres",
user = "postgres",
password = "oybek123",
host = " localhost ",
port = 5432)

and the admin port is 8080. When I write to the address bar localhost: 8080 , the admin main page opens.

There are database types, login password name and so on.

3) Here is the problem:

I type

conn = psycopg2.connect(dbname = "postgres",
user = "postgres",
password = "oybek123",
host = " localhost ",
port = 5432)


all the data from here in the column password address login and so on and the database does not open. All sorts of problems come up. Please help me find the correct config for the correct operation of the database in the web interfaces, so that by going to the admin and logging into the database I can see its content (correct) and so on

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-06-28
@ky0

But I would like to learn how to do the following. Run BOTA+DATABASE on docker.

Application containerization involves separation of entities - and for some reason you want to shove them side by side.
This is not to mention the fact that the DBMS in the docker is not a very good idea in principle, which has been repeatedly described in detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question