aiordache / demos Goto Github PK
View Code? Open in Web Editor NEWDemo resources for DockerCon
Demo resources for DockerCon
I watched the "Best Practices for Compose-managed Python Apps", thx for that! super informative and helpful.
I then tried to follow the same steps to debug the
project I'm working on: https://github.com/encointer/polkascan-os
My goal is to debug the explorer-api, which is a falcon (python) app.
So I:
The error I'm getting is: OSError: [Errno 98] Address already in use
I struggle to understand, where the problem is, I guess somehow this port is already in use, but if i change the port, the same error appears which leads me to think, that somehow the debugger or so creates 2 instances that try to connect to that port.
I'm not sure this is the correct place to file the issue, if somebody knows a solution or a better place to get answers to my question, I'd be very thankful.
Here is the error message trace log (i get it 3x):
ptvsd.enable_attach(address=('0.0.0.0',5678))
File "/usr/local/lib/python3.8/site-packages/ptvsd/attach_server.py", line 101, in enable_attach
ptvsd_enable_attach(address)
File "/usr/local/lib/python3.8/site-packages/ptvsd/_remote.py", line 76, in enable_attach
pydevd.settrace(host=host,
File "/usr/local/lib/python3.8/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2169, in settrace
_locked_settrace(
File "/usr/local/lib/python3.8/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2230, in _locked_settrace
debugger.connect(host, port) # Note: connect can raise error.
File "/usr/local/lib/python3.8/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 1060, in connect
s = start_client(host, port)
File "/usr/local/lib/python3.8/site-packages/ptvsd/pydevd_hooks.py", line 136, in _start_client
return start_client(daemon, h, p)
File "/usr/local/lib/python3.8/site-packages/ptvsd/_remote.py", line 62, in
start_client=(lambda daemon, h, port: start_daemon()),
File "/usr/local/lib/python3.8/site-packages/ptvsd/_remote.py", line 50, in start_daemon
_, next_session = daemon.start_server(addr=(host, port))
File "/usr/local/lib/python3.8/site-packages/ptvsd/daemon.py", line 161, in start_server
self._server = create_server(addr.host, addr.port)
File "/usr/local/lib/python3.8/site-packages/ptvsd/socket.py", line 79, in create_server
server.bind((host, port))
OSError: [Errno 98] Address already in use
Anca,
Thank you for writing the 3 part series: Containerized Python Development These articles along with the references that you provided have been very helpful to me.
As a bit of a newbie to all things web and Docker, I see where after opening and reading the file handler for the password file...you later close the file. Great.
What I do not see is closing the cursor and connection for the MySQL database.
Maybe you could add the following methods in the class DBManager project/app/src/server.py
def cursor_close(self):
self.cursor.close()
def connection_close(self):
self.connection.close()
These methods could then be called after database activity has ended:
@server.route('/blogs')
def listBlog():
global conn
if not conn:
conn = DBManager(password_file='/run/secrets/db-password')
conn.populate_db()
rec = conn.query_titles()
result = []
for c in rec:
result.append(c)
conn.cursor_close()
conn.connection_close()
conn = None
return flask.jsonify({"response": result})
Mike
~/samba/AWS/demos/ecsblog-demo$ docker-compose up --build
Building backend
Sending build context to Docker daemon 4.096kB
Step 1/7 : FROM python:3.7-alpine
---> cd2a4f346519
Step 2/7 : WORKDIR /app
---> Using cache
---> d7a2713b04cc
Step 3/7 : COPY requirements.txt /app
---> Using cache
---> 5e26a4331325
Step 4/7 : RUN pip3 install -r requirements.txt
---> Using cache
---> ceaeffece858
Step 5/7 : COPY main.py /app/main.py
---> Using cache
---> 4c4ceebc0966
Step 6/7 : ENTRYPOINT ["python3"]
---> Using cache
---> ea0f4de654cb
Step 7/7 : CMD ["/app/main.py"]
---> Using cache
---> 9dd4316e3ccd
Successfully built 9dd4316e3ccd
Successfully tagged ecsblog-demo_backend:latest
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Building frontend
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM nginx:alpine
---> 804f9cebfdc5
Step 2/2 : COPY nginx.conf /etc/nginx/conf.d/default.conf
---> Using cache
---> 484f90419a52
Successfully built 484f90419a52
Successfully tagged ecsblog-demo_frontend:latest
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Starting ecsblog-demo_backend_1 ... done
Starting ecsblog-demo_frontend_1 ... done
Attaching to ecsblog-demo_backend_1, ecsblog-demo_frontend_1
backend_1 | Traceback (most recent call last):
backend_1 | File "/app/main.py", line 1, in
backend_1 | from flask import Flask
backend_1 | File "/usr/local/lib/python3.7/site-packages/flask/init.py", line 14, in
backend_1 | from jinja2 import escape
backend_1 | ImportError: cannot import name 'escape' from 'jinja2' (/usr/local/lib/python3.7/site-packages/jinja2/init.py)
frontend_1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
frontend_1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
frontend_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
ecsblog-demo_backend_1 exited with code 1
frontend_1 | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
frontend_1 | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
frontend_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
frontend_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
frontend_1 | /docker-entrypoint.sh: Configuration complete; ready for start up
frontend_1 | 2022/08/24 10:47:16 [emerg] 1#1: host not found in upstream "backend" in /etc/nginx/conf.d/default.conf:4
frontend_1 | nginx: [emerg] host not found in upstream "backend" in /etc/nginx/conf.d/default.conf:4
ecsblog-demo_frontend_1 exited with code 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.