MariaDBをdocker-composeで立ち上げる。
# ./docker-compose.yml
services: db: container_name: db restart: always build: context: ./db environment: MARIADB_ROOT_PASSWORD: admin_pass MARIADB_DATABASE: database_name MARIADB_USER: db_user MARIADB_PASSWORD: db_user_pass TZ: 'Asia/Tokyo' volumes: - ./db/data:/var/lib/mysql command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci ports: - 3306:3306
# ./db/Dockerfile
FROM mariadb:latest RUN touch /var/log/mysql/mysqld.log ADD my.cnf /etc/mysql/conf.d/my.cnf ADD init.sql /docker-entrypoint-initdb.d RUN chmod 644 /etc/mysql/my.cnf
# ./db/my.cnf
[mysqld] character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci
# ./db/init.sql
-- 必要であればデータベース初期化SQLを書く
# 起動コマンド
docker-compose up docker exec -it db /bin/bash mariadb -u root -h localhost -p
# 参考
Got permission denied while trying to connect to the Docker daemon socket at 解決方法 #Ubuntu - Qiita