Starting MySQL with Docker
The official mysql image provides a ready-to-use server. The command above runs a detached container, publishes port 3306, and stores data in the named volume mysqldata. MYSQL_ROOT_PASSWORD is mandatory on first startup.
Data persistence
The internal data directory is /var/lib/mysql. Without a volume, data disappears when the container is removed. The named volume mysqldata keeps your databases across recreations.
Customization and connection
Set MYSQL_DATABASE, MYSQL_USER, and MYSQL_PASSWORD to create a database and user at startup. Open a SQL shell with docker exec -it mysql mysql -u root -p; from the host, connect to localhost:3306.