25
Using MySQL with Docker
What you need to have installed:
- Docker
With you want to learn more about Docker, you can check my blog post about it by clicking here
Downloading MySQL Image
docker image pull mysql:5.7
docker run -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v folderForVolume:/var/lib/mysql mysql:5.7
Change folderForVolume for a path from a folder to create the volume.
It will initialize your container and show you the logs while is initializing, so you can track if some errors appear in the console log.
-e will add MYSQL_ALLOW_EMPTY_PASSWORD environment variable with the value yes. With that, you can enter in mysql without a password.
-v will create a volume with the container to share some data between your pc and the container. With this, you will be able to create another container with the same data without losing any tables or queries.
-
You need to get the container ID from your mysql container.
docker container ls
-
With the container Id, now you can enter using the following command:
docker exec -it containerID bash
It will enter inside the container with a bash terminal executing.
-
Enter MySQL
mysql
If it works, then will show in the console that you are inside the mysql. To test just execute a
show databases
to check.
25