Linking python app docker and postgress docker

Linking python app docker and postgress docker

I have two docker containers running by the following commands:

I have two docker containers running by the following commands:

  • docker run --name postgres -v "/Users/xxx/Desktop/Coding/DockerMounting":/home/ -e POSTGRES_PASSWORD=xyz -d postgres
  • docker run -it -v "/Users/xxx/Desktop/Coding/DockerMounting":/home/t -p 5000:5000 --name some-app --link postgres:postgres -d xxx/ubuntu:latest

I have created the necessary user, database and table in my postgres (psql) container.

I am trying to run a python script:

import os

from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker

engine = create_engine(os.getenv("DATABASE_URL")) db = scoped_session(sessionmaker(bind=engine))

def main(): flights = db.execute("SELECT origin, destination, duration FROM flights").fetchall() for flight in flights: print(f"{flight.origin} to {flight.destination}, {flight.duration} minutes.")

if name == "main": main()

I get the following error:

  File "list.py", line 6, in <module>
    engine = create_engine(os.getenv("DATABASE_URL"))
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/init.py", line 435, in create_engine
    return strategy.create(args, *kwargs)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/strategies.py", line 56, in create
    plugins = u._instantiate_plugins(kwargs)

I know one issue is that I need to set DATABASE_URL env - but I am not sure what should be that value

python docker postgresql

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Live: Python - Docker e Docker Compose - Projeto Flask extensions

Neste episódio colocamos o serviço #python para rodar com #Docker e Docker compose e o próximo passo será a #api Multistreaming with https://restream.io/?ref...

Dockerizing a REST API in Python

Step by step Dockerizing a Python API as a single file and optimizing the size without any external dependency.

Top Python Development Companies | Hire Python Developers

After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...

Python Hello World Program - Create & Run Your First Python Program in PyCharm

Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.