What is wrong in my docker-compose?

Try to create additional database and admin for her in one service my docker-compose.
But there is a syntax error in the script... osipau and can't see where))

version: "3.0"
services:
db:
 image: mysql:5.7
 restart: always
environment:
 - MYSQL_ROOT_PASSWORD=rootpass
 - MYSQL_USER=superroot
 - MYSQL_PASSWORD=superpass123
 - MYSQL_DATABASE=gitea
entrypoint:
 sh-c "echo 'CREATE DATABASE IF NOT EXISTS nextcloud; CREATE USER 'tester'@'localhost' IDENTIFIED BY 'superpass123';\
 GRANT ALL PRIVILEGES ON * . * TO 'tester'@'localhost'; 'FLUSH PRIVILEGES'; > /docker-entrypoint-initdb.d/init.sql;\
 /usr/local/bin/docker-entrypoint.sh --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci"
#iiworks:
 # - gitea
volumes:
 /var/lib/docker/volumes/mysql:/var/lib/mysql
ports:
 - 3306:3306
April 4th 20 at 13:05
3 answers
April 4th 20 at 13:07
@Patience_Wilderman18 what you wrote in ENTRYPOINT try to run it and see the problems with the quotes around the SQL.
eg
sh-c "echo \"'A' = 'B'\" | tee /dev/null"

give
'A' = 'B'
sh-c "echo "A' = 'B" | tee /dev/null"
give
A = B
April 4th 20 at 13:09
I think it is easier to copy init.sql to image and not to generate in each run.
April 4th 20 at 13:11

Find more questions by tags MySQLDocker