Here, you can see that after executing the Docker run command, the daemon starts the MySQL starts, initializes the database, creates a root server, exposes ports, and is now ready for connection.
We just need to set a password to the MYSQL_ROOT_PASSWORD variable. We will set the default root password using this. -e: We can use this option to set environment variables inside the container.By default, the MySQL Server image exposes the 3306 port and we will connect it to the 3306 port in our own machine. -p: We can use this option to publish ports.–name: This option allows us to specify a name to our container.
Here, we have used the following options. $ docker run -name=mysql1 -p 3306:3306 -e MYSQL_ROOT_PASSWORD= -it mysql/mysql-server:latest Here, we will use the Docker run command to run a container associated with our MySQL Server image. If the image does not already exist, it will start pulling it from Dockerhub. If it finds a match, then it won’t pull the image, as that would be redundant.
When you execute the pull command, the Docker daemon will first compare the digest of this image with all the images in your local machine. Here, we will pull the mysql-server image from the MySQL repository with the latest tag. Please make sure you are logged in to Dockerhub through your command line to pull images. To do so, we will use the Docker pull command. The first step to creating a MySQL container is to pull the MySQL Server image from Dockerhub. Pull the MySQL Server Image from Dockerhub So without any further ado, let’s get started. To start with, you must have access to a Linux machine with Docker installed inside it and you should also have access to Sudo privileges.
We will see how to pull the MySQL image, create containers, and access MySQL inside it. If we want to quickly set up MySQL without eating up too many resources, hosting MySQL in Docker containers is the best solution. MySQL is an open-source, free to access, relational database server, which helps us to store, structure, and organize data ensuring accessibility. In this article, we will discuss how to run one of the most popular database servers called MySQL inside Docker containers.