Inside a new directory, create a data directory and docker-compose.yml with these rows:
version: '3'
services:
db:
container_name: docker-local-mysql
image: mysql:5.7.21
volumes:
- "./data:/var/lib/mysql"
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: password
To start the container, run docker-compose up -d. To stop & remove the container, run docker-compose down.
To connect from a MySql client use this:
Host: 127.0.0.1
Username: root
Password: password
Port: 3306