Frappe-docker - need to recreate site (drop and create) on every restart of frappe docker

I installed the dev mode of frappe-docker as we are evaluation if frappe and erpnext is a good framework for our customers.


To understand the frappe framework, went through the tutorial and created a new site library.test as per the tutorial. It worked fine the first time
But for every restart frappe-docker (using the vscode extension), it fails with the error:
The first error occurs everytime but it works and I ignore it.
The main error is followed next -
pymysql.err.OperationalError: (1045, “Access denied for user ‘_ad03fa1a016ca1c4’@‘172.19.0.5’ (using password: YES)”)

06:09:54 watch.1 | Error in: undefined
06:09:54 watch.1 | Error: ENOSPC: System limit for number of file watchers reached, watch ‘/workspace/development/frappe-bench/apps/erpnext/erpnext/public/js/website_utils.js’
06:10:14 web.1 | 172.19.0.1 - - [06/Apr/2022 06:10:14] “GET / HTTP/1.1” 500 -
06:10:14 web.1 | INFO:werkzeug:172.19.0.1 - - [06/Apr/2022 06:10:14] “GET / HTTP/1.1” 500 -
06:10:14 web.1 | Traceback (most recent call last):
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/app.py”, line 54, in application
06:10:14 web.1 | init_request(request)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/app.py”, line 125, in init_request
06:10:14 web.1 | frappe.local.http_request = frappe.auth.HTTPRequest()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/auth.py”, line 34, in init
06:10:14 web.1 | self.set_session()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/auth.py”, line 71, in set_session
06:10:14 web.1 | frappe.local.login_manager = LoginManager()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/auth.py”, line 124, in init
06:10:14 web.1 | self.make_session(resume=True)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/auth.py”, line 201, in make_session
06:10:14 web.1 | full_name=self.full_name, user_type=self.user_type)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 194, in init
06:10:14 web.1 | self.resume()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 255, in resume
06:10:14 web.1 | data = self.get_session_record()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 273, in get_session_record
06:10:14 web.1 | r = self.get_session_data()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 289, in get_session_data
06:10:14 web.1 | data = self.get_session_data_from_db()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 311, in get_session_data_from_db
06:10:14 web.1 | self.device = frappe.db.sql(‘SELECT device FROM tabSessions WHERE sid=%s’, self.sid)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 122, in sql
06:10:14 web.1 | self.connect()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 75, in connect
06:10:14 web.1 | self._conn = self.get_connection()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/mariadb/database.py”, line 90, in get_connection
06:10:14 web.1 | local_infile = frappe.conf.local_infile)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/init.py”, line 94, in Connect
06:10:14 web.1 | return Connection(*args, **kwargs)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 325, in init
06:10:14 web.1 | self.connect()
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 599, in connect
06:10:14 web.1 | self._request_authentication()
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 861, in _request_authentication
06:10:14 web.1 | auth_packet = self._read_packet()
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 684, in _read_packet
06:10:14 web.1 | packet.check_error()
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py”, line 220, in check_error
06:10:14 web.1 | err.raise_mysql_exception(self._data)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
06:10:14 web.1 | raise errorclass(errno, errval)
06:10:14 web.1 | pymysql.err.OperationalError: (1045, “Access denied for user ‘_ad03fa1a016ca1c4’@‘172.19.0.5’ (using password: YES)”)
06:10:14 web.1 |
06:10:14 web.1 | During handling of the above exception, another exception occurred:
06:10:14 web.1 |
06:10:14 web.1 | Traceback (most recent call last):
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/middlewares.py”, line 16, in call
06:10:14 web.1 | return super(StaticDataMiddleware, self).call(environ, start_response)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/werkzeug/middleware/shared_data.py”, line 220, in call
06:10:14 web.1 | return self.app(environ, start_response)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/werkzeug/middleware/shared_data.py”, line 220, in call
06:10:14 web.1 | return self.app(environ, start_response)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/werkzeug/local.py”, line 231, in application
06:10:14 web.1 | return ClosingIterator(app(environ, start_response), self.cleanup)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/werkzeug/wrappers/base_request.py”, line 237, in application
06:10:14 web.1 | resp = f(*args[:-2] + (request,))
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/app.py”, line 88, in application
06:10:14 web.1 | response = handle_exception(e)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/app.py”, line 252, in handle_exception
06:10:14 web.1 | http_status_code=http_status_code)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/website/render.py”, line 35, in render
06:10:14 web.1 | raise_if_disabled(path)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/website/render.py”, line 372, in raise_if_disabled
06:10:14 web.1 | ‘route’: [‘like’, ‘%{0}’.format(path)]
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 535, in get_all
06:10:14 web.1 | return frappe.get_all(*args, **kwargs)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/init.py”, line 1368, in get_all
06:10:14 web.1 | return get_list(doctype, *args, **kwargs)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/init.py”, line 1341, in get_list
06:10:14 web.1 | return frappe.model.db_query.DatabaseQuery(doctype).execute(None, *args, **kwargs)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 96, in execute
06:10:14 web.1 | result = self.build_and_run()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 110, in build_and_run
06:10:14 web.1 | args = self.prepare_args()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 137, in prepare_args
06:10:14 web.1 | self.build_conditions()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 333, in build_conditions
06:10:14 web.1 | self.build_filter_conditions(self.filters, self.conditions)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 354, in build_filter_conditions
06:10:14 web.1 | conditions.append(self.prepare_filter_condition(f))
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/db_query.py”, line 361, in prepare_filter_condition
06:10:14 web.1 | f = get_filter(self.doctype, f)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/utils/data.py”, line 958, in get_filter
06:10:14 web.1 | meta = frappe.get_meta(f.doctype)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/init.py”, line 820, in get_meta
06:10:14 web.1 | return frappe.model.meta.get_meta(doctype, cached=cached)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/meta.py”, line 35, in get_meta
06:10:14 web.1 | meta = Meta(meta)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/meta.py”, line 76, in init
06:10:14 web.1 | super(Meta, self).init(doctype)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/document.py”, line 115, in init
06:10:14 web.1 | super(Document, self).init(kwargs)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 66, in init
06:10:14 web.1 | self.update(d)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 89, in update
06:10:14 web.1 | self.set(key, value)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 139, in set
06:10:14 web.1 | self.extend(key, value)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 176, in extend
06:10:14 web.1 | self.append(key, v)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 153, in append
06:10:14 web.1 | value = self._init_child(value, key)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 192, in _init_child
06:10:14 web.1 | value = get_controller(value[“doctype”])(value)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 38, in get_controller
06:10:14 web.1 | module_name, custom = frappe.db.get_value(“DocType”, doctype, (“module”, “custom”), cache=True)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 408, in get_value
06:10:14 web.1 | order_by, cache=cache)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 452, in get_values
06:10:14 web.1 | out = self._get_values_from_table(fields, filters, doctype, as_dict, debug, order_by, update)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 599, in _get_values_from_table
06:10:14 web.1 | as_dict=as_dict, debug=debug, update=update)
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 122, in sql
06:10:14 web.1 | self.connect()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 75, in connect
06:10:14 web.1 | self._conn = self.get_connection()
06:10:14 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/mariadb/database.py”, line 90, in get_connection
06:10:14 web.1 | local_infile = frappe.conf.local_infile)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/init.py”, line 94, in Connect
06:10:14 web.1 | return Connection(*args, **kwargs)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 325, in init
06:10:14 web.1 | self.connect()
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 599, in connect
06:10:14 web.1 | self._request_authentication()
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 861, in _request_authentication
06:10:14 web.1 | auth_packet = self._read_packet()
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 684, in _read_packet
06:10:14 web.1 | packet.check_error()
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py”, line 220, in check_error
06:10:14 web.1 | err.raise_mysql_exception(self._data)
06:10:14 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
06:10:14 web.1 | raise errorclass(errno, errval)
06:10:14 web.1 | pymysql.err.OperationalError: (1045, “Access denied for user ‘_ad03fa1a016ca1c4’@‘172.19.0.5’ (using password: YES)”)
06:10:14 web.1 | 172.19.0.1 - - [06/Apr/2022 06:10:14] “GET /?debugger=yes&cmd=resource&f=style.css HTTP/1.1” 200 -
06:10:14 web.1 | INFO:werkzeug:172.19.0.1 - - [06/Apr/2022 06:10:14] “GET /?debugger=yes&cmd=resource&f=style.css HTTP/1.1” 200 -
06:10:14 web.1 | 172.19.0.1 - - [06/Apr/2022 06:10:14] “GET /?debugger=yes&cmd=resource&f=jquery.js HTTP/1.1” 200 -
06:10:14 web.1 | INFO:werkzeug:172.19.0.1 - - [06/Apr/2022 06:10:14] “GET /?debugger=yes&cmd=resource&f=jquery.js HTTP/1.1” 200 -
06:10:14 web.1 | 172.19.0.1 - - [06/Apr/2022 06:10:14] “GET /?debugger=yes&cmd=resource&f=debugger.js HTTP/1.1” 200 -
06:10:14 web.1 | INFO:werkzeug:172.19.0.1 - - [06/Apr/2022 06:10:14] “GET /?debugger=yes&cmd=resource&f=debugger.js HTTP/1.1” 200 -
06:10:16 web.1 | 172.19.0.1 - - [06/Apr/2022 06:10:16] “GET /?debugger=yes&cmd=resource&f=console.png HTTP/1.1” 200 -
06:10:16 web.1 | INFO:werkzeug:172.19.0.1 - - [06/Apr/2022 06:10:16] “GET /?debugger=yes&cmd=resource&f=console.png HTTP/1.1” 200 -
06:10:16 web.1 | 172.19.0.1 - - [06/Apr/2022 06:10:16] “GET /?debugger=yes&cmd=resource&f=console.png HTTP/1.1” 200 -
06:10:16 web.1 | INFO:werkzeug:172.19.0.1 - - [06/Apr/2022 06:10:16] “GET /?debugger=yes&cmd=resource&f=console.png HTTP/1.1” 200 -
06:10:18 web.1 | 172.19.0.1 - - [06/Apr/2022 06:10:18] “GET / HTTP/1.1” 500 -
06:10:18 web.1 | INFO:werkzeug:172.19.0.1 - - [06/Apr/2022 06:10:18] “GET / HTTP/1.1” 500 -
06:10:18 web.1 | Traceback (most recent call last):
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/app.py”, line 54, in application
06:10:18 web.1 | init_request(request)
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/app.py”, line 125, in init_request
06:10:18 web.1 | frappe.local.http_request = frappe.auth.HTTPRequest()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/auth.py”, line 34, in init
06:10:18 web.1 | self.set_session()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/auth.py”, line 71, in set_session
06:10:18 web.1 | frappe.local.login_manager = LoginManager()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/auth.py”, line 124, in init
06:10:18 web.1 | self.make_session(resume=True)
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/auth.py”, line 201, in make_session
06:10:18 web.1 | full_name=self.full_name, user_type=self.user_type)
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 194, in init
06:10:18 web.1 | self.resume()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 255, in resume
06:10:18 web.1 | data = self.get_session_record()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 273, in get_session_record
06:10:18 web.1 | r = self.get_session_data()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 289, in get_session_data
06:10:18 web.1 | data = self.get_session_data_from_db()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/sessions.py”, line 311, in get_session_data_from_db
06:10:18 web.1 | self.device = frappe.db.sql(‘SELECT device FROM tabSessions WHERE sid=%s’, self.sid)
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 122, in sql
06:10:18 web.1 | self.connect()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/database.py”, line 75, in connect
06:10:18 web.1 | self._conn = self.get_connection()
06:10:18 web.1 | File “/workspace/development/frappe-bench/apps/frappe/frappe/database/mariadb/database.py”, line 90, in get_connection
06:10:18 web.1 | local_infile = frappe.conf.local_infile)
06:10:18 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/init.py”, line 94, in Connect
06:10:18 web.1 | return Connection(*args, **kwargs)
06:10:18 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 325, in init
06:10:18 web.1 | self.connect()
06:10:18 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 599, in connect
06:10:18 web.1 | self._request_authentication()
06:10:18 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 861, in _request_authentication
06:10:18 web.1 | auth_packet = self._read_packet()
06:10:18 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/connections.py”, line 684, in _read_packet
06:10:18 web.1 | packet.check_error()
06:10:18 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/protocol.py”, line 220, in check_error
06:10:18 web.1 | err.raise_mysql_exception(self._data)
06:10:18 web.1 | File “/workspace/development/frappe-bench/env/lib/python3.7/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
06:10:18 web.1 | raise errorclass(errno, errval)
06:10:18 web.1 | pymysql.err.OperationalError: (1045, “Access denied for user ‘_ad03fa1a016ca1c4’@‘172.19.0.5’ (using password: YES)”)

If I do “docker ps” on my ubunut machine - all containers are up inlcuding mariaDB
I then do “bench drop-site” and drop the library.test site
and recreate it using “bench new-site”. It then works
Can also log in to “bench --site library.test mariadb”
But every restart , this also fails
can someone help in understanding what goes wrong for every restart. Frappe seems to delete the db privileges for the Administrator user

Make sure you use --no-mariadb-socket when you create new site.
If you wish to fix the current site check this https://github.com/frappe/frappe_docker/blob/main/docs/troubleshoot.md#fixing-mariadb-issues-after-rebuilding-the-container

container IP changes after restart. mariadb gives site access to the container ip that created it. --no-mariadb-socket sets the db user’s host to wildcard %. This allows access from any IP.

Thanks for the pointers.First time I saw an official doc on troubleshooting!
I tired the above and got an error on Update. The errors says it is due to lack of rights to the user. Which is weird as I logged in as root

ERROR 1356 (HY000): View ‘mysql.user’ references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

However, I did a select to check the above tables and I can see how the Host is set to 3 Ip’s - 172.19.0.2,3,5 for the same db_user. There are 3 entries for the user
So select works but not updates!
For now, I see that it works on restarts also. Probably as you explained the container Ip is set to one of the above IP.
If it fails next time, I will recreate the site and try to update.
Any idea , why Update statement is not working for ‘root’?

try mysql.global_priv instead of mysql.user.