Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 22, 2022 05:03 pm GMT

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

Lets execute the container for an image that we did download. At first, we dont 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 dont forget.


Original Link: https://dev.to/jessicanathany/how-to-create-database-mysql-with-docker-1ph3

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To