Have you ever worked with containers? If you did you should already know what great tool are and the huge amount of benefits they provide. Look how easy it is to install MySQL using docker containers.
Docker Install MySQL of 8 and 5.7) 2021-07-03 01:08:30. This article describes how to deploy an MySQL database and remote access configuration using Docker. Installing MySQL. Pull mirror image. Use the following command to pull the mirror image of the MySQL database: $ sudo docker pull mysql $ sudo docker pull mysql:5.7.
- Trying to install MySQL (&Wordpress) Close. Posted by 6 minutes ago. Trying to install MySQL (&Wordpress) Hi. Docker exec pihole chown -R www-data:pihole.
- Install and Start Dockerized MySQL. Docker containers are stateless. So, if you use a Containerized MySQL, then you will lose all your saved Data once you restart the container. One way to avoid the issue is to create a docker volume and attach it to your MySQL container. Here are the commands to create a MySQL container including attached.
- Step 1 — Installing MySQL. Let's start by installing the MySQL database first. We need to have it up & running before we can connect with phpMyAdmin. We'll grab the image from the official MySQL repository on Docker Hub using docker pull command. As of writing, the latest version of MySQL is 8.0.19.
In this post we are going to install MySQL and phpMyAdmin using docker containers. In details we are going to perform the following actions:
- Pull the MySQL docker container
- Run the MySQL docker container
- Check the status of the MySQL docker container
- Pull the phpMyAdmin docker container
- Run the phpMyAdmin docker container
- Access MySQL via phpMyAdmin
I tested this procedure on Windows and Mac using docker engine v19.03.13.
Pull the MySQL docker container
Pulling a container image is really easy. We just need to open the docker hub website, search for the MySQL image we want to pull and execute the pull command in the command prompt.
docker pull mysql:latest
After entering the Pull command, docker will start downloading the latest version of the MySQL image.
Just to be clear: we are not downloading the latest version of MySQL but the latest version of the MySQL container.
During the execution of the pull command the full image will be separated into multiple small files. This has the benefit of speeding up the download pulling single files in parallel. This is how the command prompt should look like :
The download will end when all file will be in Pull complete. The docker cli will then combine all file together and notify when the action is completed.
Run the MySQL docker container
The fact we completed the download of the image does not mean we have a container up and running. For now we just download a simple file. Now we have to use the docker cli to execute the run command and initialize our container. Here below the command:
- -v: indicates where on your local machine you want to persist the data you are saving in the DB. The sample shows a volume mounted on a Windows machine. Literally it means that the container path /var/lib/mysql will be saved on C:Dockermysql. If you don’t set this parameter the container will not persist the data. After restarting the container you will lose all work done.
- –name: is the name of your local container. Free to choose what you like most. In the sample I called mine MySQLContainer.
- -e: specifies runtime variables you need to set to initialize the MySQL container. In this case, we are assigning a value to the MYSQL_ROOT_PASSWORD variable. The container will then use this value to configure the password for the default MySQL user. I use MyPassword , I am sure you can do something better in term of security!
- -d: this parameter tells docker to start the container in “detached” mode. The container will run in the background and the terminal wont show any application output. This is useful when we want to run container for very long time. In case we do not want to set this parameter the container will run in “attached” mode which means it will be linked with the current command prompt session.
As result the docker will output a container id. This means that the container is up and running in the background.
Check the status of the MySQL docker container
Just to be sure that all we have done so far is working, we can verify the status of the container by simply running the following command:
As result docker will output in the command prompt the list of all active containers. As you can see from the screenshot below MySQL is running on port 3306.
In case you want to get some more insight on what the container is doing in the background you can run the following two commands followed by the container name:
docker logs MySQLContainer
docker inspect MySQLContainer
Pull phpMyAdmin docker container
Install Mysql With Docker Windows 10
phpMyAdmin is the administration tool for MySQL. It is a portable web application easy to be containerized. As we did before for the MySQL container, we just need to point to docker hub, search for the latest version of the phpMyAdmin container image and start the pull process.
Once done with the download, we will proceed with the next step. The run command.
Run phpMyAdmin docker container
Here the run command:
As you probably already noticed, we have a different set of parameters:
- –name: is the name of your local container. Free to choose what you like most. In the sample I called mine MySQLAdmin.
- -d: this parameter tells docker to start the container in “detached” mode. The container will run in the background and the terminal wont show any application output. Running the container in the background is useful when we want to run container for very long time. In case we do not want to set this parameter the container will run in “attached” mode which means it will be linked with the current command prompt session.
- –link: it links the phpMyAdmin to the a MySQL container. Here you should use the name of the MySQL container you specified before. In my case was MySQLContainer
- -p: this parameter will set the listening port for the web portal. I used 8080 but as usual, you are free to choose the port number you like.
To verify that everything is working, we can now open the browser and navigate to http://localhost:8080/. The browser will show a page like the one showed in the screenshot below:
In order to login we should provide the two fields Username and Password. We can use the following values:
- Username: root.
- Password: value provided with the MYSQL_ROOT_PASSWORD variable when running the MySQL container. I used MyPassword
With the username and the password correctly filled in and after pressing the Go button we should be able to login and see the following page:
I really enjoy working with containers and I really hope you feel the same way too! I will definitely write more about it. and please, feel free to leave any comment.
Thanks for reading.
In this article, we are going to see a step-by-step tutorial on how to run a MySQL database in a Docker Container.
1.Downloading a MySQL Server Docker Image
Install Mysql With Docker Free
To download the image, open the command line and type this command:
The :latest tag will download the latest version of MySQL. If you want do download a specific version, simply replace the
latest (Ex: mysql-server :8.0)
2.Start a MySQL Container in Docker
The next step is to run a container in Docker with the MySQL image. To do this, execute the next command:
Install Mysql With Docker Linux
Let’s break down this command to understand it better:
- run - will run a new command in a new Docker container
- –name - will give a name to the new container created
- -p - will make the internal docker port visible outside docker
- -e - will change the root password. Here you can insert whatever password you want
- mysql/mysql-server:8.0 - will specify what image to run in the newly created container
To verify if the container was created and running, we can execute a docker ps (process status) command:
This will list all the running containers as shown above.
In the status column of the result from above, you can see the (health: starting) mention. After the container is initialized
and ready to run, you will se it change to (healthy).
3.Connecting to MySQL Server from within the container
To connect, we will first run the next command:
This will require the root password set in the previous step. After inserting the password, you should be inside MySQL
Type exit to leave the program.
4.Stopping the MySQL container
To stop the container, simply execute the next command:
5.Deleting the MySQL container
Install Mysql Docker Ubuntu
To delete the container, make sure that it is stopped. Then, execute this command:
Install Mysql With Docker Download
Share this blog post on Twitter, Facebook, and LinkedIn