I am trying to run trac on one container and install MariaDB on another container, on the trac container when I am trying to initialize the environment using trac-admin /path/to/env initenv I am getting the following error during specifying the database connection string which is running on another container:
Database connection string [sqlite:db/trac.db]> mysql://root:[email protected]:3306/trac
Initenv for '/usr/local/trac1' failed.
Failed to create environment.
'NoneType' object has no attribute 'encoding'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/trac/admin/console.py", line 431, in do_initenv
options=options)
File "/usr/local/lib/python2.7/dist-packages/trac/core.py", line 141, in __call__
self.__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/trac/env.py", line 259, in __init__
self.create(options)
File "/usr/local/lib/python2.7/dist-packages/trac/env.py", line 566, in create
DatabaseManager(self).init_db()
File "/usr/local/lib/python2.7/dist-packages/trac/db/api.py", line 285, in init_db
connector.init_db(**args)
File "/usr/local/lib/python2.7/dist-packages/trac/db/mysql_backend.py", line 133, in init_db
params)
File "/usr/local/lib/python2.7/dist-packages/trac/db/mysql_backend.py", line 118, in get_connection
cnx = MySQLConnection(path, log, user, password, host, port, params)
File "/usr/local/lib/python2.7/dist-packages/trac/db/mysql_backend.py", line 413, in __init__
host=host, port=port, **opts)
File "/usr/local/lib/python2.7/dist-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 285, in __init__
self.encoding = charset_by_name(self.charset).encoding
AttributeError: 'NoneType' object has no attribute 'encoding'
Created and granted permissions to the trac database using the following commands:
MariaDB [(none)]> CREATE DATABASE trac DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
Query OK, 1 row affected (0.007 sec)
MariaDB [(none)]> GRANT ALL ON trac.* TO [email protected] IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.026 sec)
Dockerfile for trac:
# This is a Dockerfile for trac
FROM quay.io/official-images/debian:bullseye-slim
LABEL description="Custom httpd container image for running trac"
RUN apt-get update \
&& apt-get install -y aptitude vim git wget gcc apache2 python2 python2-dev unzip
RUN apt-get install -y default-libmysqlclient-dev
RUN wget https://bootstrap.pypa.io/pip/2.7/get-pip.py \
&& python2 get-pip.py
RUN python2 -m pip install setuptools Jinja2 babel Pygments docutils pytz textile PyMySQL trac
EXPOSE 80 8000
ENV LogLevel "info"
ADD index.html /var/www/html
#RUN trac-admin /usr/local/trac initenv trac mysql://root:[email protected]:3306/trac
#RUN tracd --port 8000 /usr/local/trac &
ENTRYPOINT ["apachectl"]
CMD ["-D", "FOREGROUND"]
Dockerfile for MariaDB:
# This is a Dockerfile for MariaDB to be used with trac
FROM docker.io/mariadb:latest
LABEL description="Custom mariadb container image for running trac"
ARG MARIADB_USER=db_user
ARG MARIADB_ROOT_PASSWORD=db_pw
ARG MARIADB_DATABASE=db_name
ENV PACKAGES openssh-server openssh-client
ENV MARIADB_USER $MARIADB_USER
ENV MARIADB_ROOT_PASSWORD $MARIADB_ROOT_PASSWORD
ENV MARIADB_DATABASE $MARIADB_DATABASE
RUN mkdir /db_backup
ADD trac.sql /db_backup
RUN apt-get update && apt-get install -y $PACKAGES
EXPOSE 3306
CMD ["mysqld"]
I figured it out myself, while I was trying to create the database using the command specified in the
tracdocumentation (mentioned in the question) I was getting the followingcharacter_set_databaseandcollation_database:The following command should be used to create the database with the correct encodings:
Results: