Cómo desplegar un contenedor Docker de MySQL y conectarse a él
Many web applications and services depend on databases, and chances are, your business relies on them too. If you don't want the hassle of setting up a dedicated server to host a remote database, a containerized solution can be a game changer. While it may not be ideal for enterprise-level apps that require scalability, it can be a real boon for medium and smaller instances, especially for those without access to dedicated database server hardware.
In this article, I will walk you through the process of deploying a MySQL Docker container, allowing you to connect to it from other containers or applications. Whether you're using Ubuntu 16.10 Server or any other operating system with Docker, the steps remain the same as long as Docker is running.
Pulling the MySQL Docker Image
The first step is to pull down the relevant MySQL image. For this demonstration, I'm going with the latest release of MySQL. However, if you require a specific release, you can substitute the latest tag with versions like 5.5, 5.6, 5.7, or 8.0.
To pull the MySQL Docker image, use the following command:
docker pull mysql/mysql-server:latest
NOTE: Please ensure that the user issuing the above command is a member of the docker group. If not, run the command sudo usermod -a -G docker USERNAME (replace USERNAME with the appropriate user). After completing this step, log out and log back in to proceed.
Deploying the MySQL Container
With the MySQL image downloaded, it's time to deploy the container. Use the following command:
docker run --name=mysql01 -d mysql/mysql-server:latest
In the above command, I've named the container as mysql01. Feel free to use any name you prefer to identify your container.
You can then verify that your MySQL container is running by executing the command docker ps
(Figure A).
Figure A
Microsoft lanza servicio gratuito de almacenamiento en la nube para usuarios de WindowsThe MySQL Root Password
Typically, during or after the MySQL installation on a Linux machine, you would be prompted to create a database admin password. However, since we have deployed a Docker container that already comes with the database installed and running, we need to know how to access it without having set a password ourselves. Fortunately, this process is quite straightforward.
To obtain the randomly generated root user password for MySQL, use the command:
docker logs mysql01
Within the output of this command, you will find the root user password for MySQL (Figure B).
Figure B
Cómo evitar que el archivo de registro de transacciones en SQL Server crezca demasiado grandeLogging into the MySQL Server
The next step is to log into the containerized MySQL server using the following command:
docker exec -it mysql01 mysql -uroot -p
You will be prompted to enter the root user's password, which you obtained from the previous step. Once inside the MySQL server, you can change the password using the command:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
Replace 'newpassword' with your desired password. To exit the MySQL shell, use the command 'exit'. Your containerized MySQL database is now ready to use.
Debería su organización migrar a Google Apps desde Microsoft ExchangeWelcome to the Simplicity of Containers
And that's all there is to deploying a MySQL container. If you don't have spare hardware for a dedicated database server or simply need a testing environment, Docker simplifies the deployment of a containerized database server. Give it a try and see how it perfectly suits your needs.
En Newsmatic nos especializamos en tecnología de vanguardia, contamos con los artículos mas novedosos sobre Nube, allí encontraras muchos artículos similares a Cómo desplegar un contenedor Docker de MySQL y conectarse a él , tenemos lo ultimo en tecnología 2023.
Artículos Relacionados