Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make db service in docker-compose use non-root user

See original GitHub issue


  • CTFd Version/Commit: b5632f9
  • Operating System: Docker v18.09.5
  • Web Browser and Version: not related

What happened?

Access denied for 'ctfd'@'%' to database 'ctfd'

What did you expect to happen?

Connect to CTFd database using ctfd user instead of using root.

How to reproduce your issue

docker-compose up -d
docker-compose logs -f

Any associated stack traces or error logs

ctfd_1   | [SQL: CREATE DATABASE ctfd CHARACTER SET = 'utf8mb4']
ctfd_1   | (Background on this error at:
ctfd_1   | Waiting for db: to be ready
ctfd_1   | db is ready
ctfd_1   | Traceback (most recent call last):
ctfd_1   |   File "", line 8, in <module>
ctfd_1   |     app = create_app()
ctfd_1   |   File "/opt/CTFd/CTFd/", line 137, in create_app
ctfd_1   |     url = create_database()
ctfd_1   |   File "/opt/CTFd/CTFd/utils/migrations/", line 26, in create_database
ctfd_1   |     create_database_util(url, encoding="utf8mb4")
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy_utils/functions/", line 577, in create_database
ctfd_1   |     result_proxy = engine.execute(text)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/", line 2166, in execute
ctfd_1   |     return connection.execute(statement, *multiparams, **params)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/", line 982, in execute
ctfd_1   |     return self._execute_text(object_, multiparams, params)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/", line 1155, in _execute_text
ctfd_1   |     parameters,
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/", line 1248, in _execute_context
ctfd_1   |     e, statement, parameters, cursor, context
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/", line 1466, in _handle_dbapi_exception
ctfd_1   |     util.raise_from_cause(sqlalchemy_exception, exc_info)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/", line 383, in raise_from_cause
ctfd_1   |     reraise(type(exception), exception, tb=exc_tb, cause=cause)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/", line 1244, in _execute_context
ctfd_1   |     cursor, statement, parameters, context
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/", line 552, in do_execute
ctfd_1   |     cursor.execute(statement, parameters)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/pymysql/", line 170, in execute
ctfd_1   |     result = self._query(query)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/pymysql/", line 328, in _query
ctfd_1   |     conn.query(q)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/pymysql/", line 516, in query
ctfd_1   |     self._affected_rows = self._read_query_result(unbuffered=unbuffered)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/pymysql/", line 727, in _read_query_result
ctfd_1   |
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/pymysql/", line 1066, in read
ctfd_1   |     first_packet = self.connection._read_packet()
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/pymysql/", line 683, in _read_packet
ctfd_1   |     packet.check_error()
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/pymysql/", line 220, in check_error
ctfd_1   |     err.raise_mysql_exception(self._data)
ctfd_1   |   File "/usr/local/lib/python2.7/site-packages/pymysql/", line 109, in raise_mysql_exception
ctfd_1   |     raise errorclass(errno, errval)
ctfd_1   | sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1044, u"Access denied for user 'ctfd'@'%' to database 'ctfd'")
ctfd_1   | [SQL: CREATE DATABASE ctfd CHARACTER SET = 'utf8mb4']
ctfd_1   | (Background on this error at:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

ColdHeatcommented, Jun 21, 2019

I decided the best solution for this now is to continue using the root user but begin migrating to an unprivileged user and allow the usage of the unprivileged user.

ColdHeatcommented, May 30, 2020

Closed with #1457

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a non-root user for microservice to connect to ...
Your user script define user in admin database, ,so you need to authenticate against this admin database to connect.
Read more >
Ruby with Docker Compose as a Non-root User
A pattern to run ruby with docker compose as a non-root user. This pattern alleviates the pain and security issues of root execution...
Read more >
Run a PostgreSQL container as a non-root user in OpenShift
In this blog post I want to point out a simple topic: How to run a simple PostgreSQL Docker image as a non-productive...
Read more >
Add non-root user to a container - Visual Studio Code
Docker Desktop for Windows: Inside the container, any mounted files/folders will appear as if they are owned by root but the user you...
Read more >
Up and Running with MySQL in Docker | Red's Digressions
docker compose up -d · # connect shell to server docker exec -it mysql_dumps_mysql-dev_1 mysql -uroot -p · ALTER USER 'root'@'localhost' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found