The process of setting up a Mysql container with Docker Desktop and connecting from the host machine

Docker Desktop version is 4.32.0

Get Mysql Image

There is a search bar at the header.
Input mysql and you will see a list containing mysql.
Click on it.

You will see the Pull button and click it.
If you wanna pull the image via the term…


This content originally appeared on DEV Community and was authored by lnoueryo

Docker Desktop version is 4.32.0

Get Mysql Image

There is a search bar at the header.
Input mysql and you will see a list containing mysql.
Click on it.
A search bar

A list containing mysql

You will see the Pull button and click it.
If you wanna pull the image via the terminal, use the following command:

docker pull {image_name}

The Pull button

Set Up Environmental Variables

After the image is downloaded, go to the images page from the drawer and you will see the MySQL image listed.
Click the run buttn.

The MySQL image listed

In the Optional settings, input the values as below and click the Run button

The Optional settings

The command is as follows:

docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=password -p 3306:3306 -d mysql:latest

Connect To The Mysql Container From The Host Machine

You might think that you can connect with the following command:

mysql -u root -p

But actually you can't.
The error message will be:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I asked ChatGPT about the reason for the error and the answer is you need to add the host IP as below.

mysql -u root -p -h 127.0.0.1

And now you can connect to it.
Thank You!!


This content originally appeared on DEV Community and was authored by lnoueryo


Print Share Comment Cite Upload Translate Updates
APA

lnoueryo | Sciencx (2024-07-14T03:40:58+00:00) The process of setting up a Mysql container with Docker Desktop and connecting from the host machine. Retrieved from https://www.scien.cx/2024/07/14/the-process-of-setting-up-a-mysql-container-with-docker-desktop-and-connecting-from-the-host-machine/

MLA
" » The process of setting up a Mysql container with Docker Desktop and connecting from the host machine." lnoueryo | Sciencx - Sunday July 14, 2024, https://www.scien.cx/2024/07/14/the-process-of-setting-up-a-mysql-container-with-docker-desktop-and-connecting-from-the-host-machine/
HARVARD
lnoueryo | Sciencx Sunday July 14, 2024 » The process of setting up a Mysql container with Docker Desktop and connecting from the host machine., viewed ,<https://www.scien.cx/2024/07/14/the-process-of-setting-up-a-mysql-container-with-docker-desktop-and-connecting-from-the-host-machine/>
VANCOUVER
lnoueryo | Sciencx - » The process of setting up a Mysql container with Docker Desktop and connecting from the host machine. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/14/the-process-of-setting-up-a-mysql-container-with-docker-desktop-and-connecting-from-the-host-machine/
CHICAGO
" » The process of setting up a Mysql container with Docker Desktop and connecting from the host machine." lnoueryo | Sciencx - Accessed . https://www.scien.cx/2024/07/14/the-process-of-setting-up-a-mysql-container-with-docker-desktop-and-connecting-from-the-host-machine/
IEEE
" » The process of setting up a Mysql container with Docker Desktop and connecting from the host machine." lnoueryo | Sciencx [Online]. Available: https://www.scien.cx/2024/07/14/the-process-of-setting-up-a-mysql-container-with-docker-desktop-and-connecting-from-the-host-machine/. [Accessed: ]
rf:citation
» The process of setting up a Mysql container with Docker Desktop and connecting from the host machine | lnoueryo | Sciencx | https://www.scien.cx/2024/07/14/the-process-of-setting-up-a-mysql-container-with-docker-desktop-and-connecting-from-the-host-machine/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.