DEV Community

Jéssica Nathany
Jéssica Nathany

Posted on

How to create database MySQL with Docker

Image description

I'll to show how to create an local database MySQL with Docker, in yours Windows. It is necessary has the last version Docker intalladed in your machine.

1st step: Dowload the MySQL image

Let's download the latest MySQL image to the Docker hub, type the following command below:

docker pull mysql/mysql-server

2st step: Execute the container

Let´s execute the container for an image that we did download. At first, we don´t configure environment variables, at moment just execute the MySQL for default users without a password. Before executing the command, you can create a directory with the name mysql. Write the command below in your terminal.

Note: create only the directory C:/mysql for default, the MySQL to need has folder */var/lib/mysql, this directory the MySQL will save your database.*

Write the command below

docker ryn -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -v C:/mysql/var/lib/mysql mysql

Image description

Image description

3st step: Getting the container's IP

For discovery the container IP, write command docker container ls for verify the containers that running and copy the ID the container, using the command docker container inpect ID_CONTAINER.

Image description

4st step: Acess database from container

To access the database through the container, we need to go inside the container, so write the command below

docker exec -it ID_CONTAINER

Image description

Image description

Already. We have a datbase MySQL in container Docker. Now you can create your database and tables.

Image description

Image description

Conslusion

This is a sample example for you create database with docker. Of course this example I created the sample database, but you can configure user and password in your database.

Write for don´t forget.

Top comments (0)