23

I have an issue with the official dockerized image of Mariadb.

When my applications tries to make some queries I got the following error :

DB Error: unknown error QUERY : INSERT INTO

It seems this error comes from the SQL_MODE, which is set as follow in this image :

STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,
NO_ENGINE_SUBSTITUTION

I have a normal Linux Server and with mariadb installed and i don't have this STRICT_TRANS_TABLES value in my SQL_mode. And my application is working without any problem.

How can I remove the STRICT_TRANS_TABLES value in my container when I run docker-compose with my docker-compose file without the need of a custom dockerfile?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aurelien
  • 688
  • 1
  • 9
  • 22

1 Answers1

64

In your docker-compose.yml set command: --sql_mode="".
Here is an example:

db-service:
    build:
      context: .
      dockerfile: db.dockerfile
    image: example/repo:db
    ports:
      - "3306:3306"
    volumes:
      - ./data/db-data:/var/lib/mysql
      - ./data/db-init:/docker-entrypoint-initdb.d/
    ports:
      - "3306:3306"
    environment:
        MYSQL_USER: root
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: your_database
    command: mysqld --sql_mode="" --character-set-server=utf8 --collation-server=utf8_slovenian_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0
    restart: on-failure
    networks:
      - yournet

It works fine for me.

doublesharp
  • 26,888
  • 6
  • 52
  • 73
Heril Muratovic
  • 1,940
  • 6
  • 25
  • 46