In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "Docker how to get MySQL image". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to get MySQL image from Docker".
6. Basics
In this section, we take running an MySQL instance as an example to introduce the basic usage.
Use docker-- help to view all supported commands 6. 1. 0. Get MySQL image
First, let's get the MySQL image from hub.docker.com.
There are two ways, one is to use the search command:
Root@ubuntu:~# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relati... 1253 [OK] mariadb MariaDB is a community-developed fork of M... 280 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Crea... 58 [OK] centurylink/mysql Image containing mysql. Optimized to be li... 29 [OK]...
In addition, we can also check the web page for more detailed instructions:
STARS indicates the number of favorites, PULLS indicates the number of downloads, and OFFICIAL indicates the official image (here indicates whether it is officially released by MySQL)
Let's download the first official image.
Root@ubuntu:~# docker pull mysql Pulling repository mysql 196db1908492: Download complete 575489a51992: Download complete... Status: Downloaded newer image for mysql:latest
The named format of the Docker image, the image name 6.2. View native image
View all images of this machine
Root@ubuntu:~# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE mysql 5.7 196db1908492 6 days ago 359.8 MB mysql 5.7.9 196db1908492 6 days ago 359.8 MB mysql Latest 196db1908492 6 days ago 359.8 MB... 6.3. Run MySQL Mirror
Run MySQL Mirror
Root@ubuntu:~# docker run-- name app1-db-e MYSQL_ROOT_PASSWORD=123456-d mysql:5.7 2dee953f85d697ffcb78ac795f06e1a22731ae373b154178ea6220ce9b9c6e04
-- name specifies the container name,-e specifies some special variables, and-d indicates background operation (service) 6.4. View native containers
View all the running containers on this machine
Root@ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2dee953f85d6 mysql:5 "/ entrypoint.sh mysq 6 seconds ago Up 5 seconds 3306/tcp app1-db
Docker ps-a can view all containers (including those that are not running)
And then, how to connect? We need an IP and a port, but the above operation does not expose the port, so we need to rerun a container
Docker currently (v1.7) does not support binding ports for containers. If you need this, please see how to add access port 6.5 for running containers. Delete MySQL Container
Let's delete the container just now.
Root@ubuntu:~# docker rm-f app1-db app1-db
-f means to force the deletion of a running container
This deletes all data in the container. Unscientific? What about keeping some data (such as the database file here) when I want to delete the container? Let's look down:
Rerun the MySQL image
Root@ubuntu:~# docker run-name app1-db-e MYSQL_ROOT_PASSWORD=123456-d-p 3308 MYSQL_ROOT_PASSWORD=123456 3306-v / opt/mysql_data:/var/lib/mysql mysql:5.7 1add96f289a1b8744500a4a6709af6e2e0628b97797e8470be75efe67e2005f4
-p means to map the externally accessed port 3308 to the container port 3306, because the MySQL image allows port 3306 to be opened by default (how do I know? Look at its dockerfile, which will be explained later), so you can also use-P directly, so that external access 3306 is also mapped to port 3306 of the container.
The-v parameter can map the directory of the host to the directory within the container. In the above example,-v / opt/mysql_data:/var/lib/mysql maps the host / opt/mysql_data to the container / var/lib/mysql (the data directory of MySQL is known to be this directory), which ensures that the data of the corresponding directory will not be deleted when the container is deleted (because this directory is on the host), which is important. In practice, almost all containers have to do this mapping!
What about IP when you have the port? IP is actually the IP of your docker host.
The access mechanism of Docker simply states that all external services of Docker use the specific port of host IP+. When a request is initiated, it will be forwarded to the corresponding container for processing according to the port rules when the container is created through the iptables on the host side.
All right, now let's do a connection test and pass
6.6. Stop / run / restart the MySQL container
Of course, we can also stop / run / restart the container:
Root@ubuntu:~# docker stop app1-db app1-db root@ubuntu:~# docker start app1-db app1-db root@ubuntu:~# docker restart app1-db app1-db thank you for your reading. The above is the content of "how to obtain MySQL image by Docker". After the study of this article, I believe you have a deeper understanding of how Docker obtains MySQL image, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.