Basic setup
docker-compose.yml
version: "3"
services:
mysql:
image: "mysql"
container_name: "mysql"
environment:
- MYSQL_ROOT_PASSWORD=shhhht
- MYSQL_DATABASE=project
ports:
- 3306:3306
Note: the MYSQL_DATABASE
variable allows you to specify the name of a database to be created on image startup.
Interacting with the service
To start the service:
docker compose up -d
To stop the service:
docker compose down
Working with the MySQL shell
To access the shell:
docker exec -it mysql mysql --user=root --password=shhhht
docker exec -it
- run a command to a running containermysql
- the container namemysql
- the command--user=root
- the user--password=shhhht
- the password
To exit the shell:
exit