Various problems encountered by novices in loading mysql into docker
- 2021-12-04 20:06:30
- OfStack
Preface
Recently, the computer is often shut down for a long time, and it is always necessary to press the power button to shut down forcibly. I don't know what happened.
Later, when I checked the log when I shut down, I found that mysql couldn't stop. This is annoying! What to do? I searched the Internet and didn't find any good solution. Can't you press the power button for a long time every time you shut down? The computer is so expensive, besides, it is my own computer. What if it breaks down?
Delete mysql? As a code, the computer can not install mysql ah, everyday to use! In a virtual machine? This seems to be feasible, regardless of whether you can turn off mysql, I will stop the virtual machine on the line. Then I looked at virtualbox, which has not been opened for more than one year on my computer, and thought it was not suitable to dress here. My computer hard disk is 250G, just to install an mysql, I have to give it a hard disk of 10 G, and then give it 2G memory, which is inappropriate. Then how to do it? Buckled my mouse, think of the previous year to follow the trend of research docker, um ~, you.
Start installing mysql into docker
Installing docker
docker command is I can not remember ~, the Internet search installation command, or very simple. Command 1: Just knock and brush. (My computer is equipped with deepin system)
wget -qO- https://get.docker.com/ | sh
Then you need to start it up, which is also a command ~
sudo service docker start
docker Running Ubuntu
docker is installed, how to run a system inside? Only docker can't run mysql! At this time, you need to download a system image, and the image of Ubuntu is used here. First, you need to search for 1. You can search for images in the market with the following command.
// Command
sudo docker search ubuntu
// Results
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys … 9583 [OK]
dorowu/ubuntu-desktop-lxde-vnc Docker image to provide HTML5 VNC interface … 304 [OK]
rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi … 217 [OK]
consol/ubuntu-xfce-vnc Ubuntu container with "headless" VNC session … 179 [OK]
ubuntu-upstart Upstart is an event-based replacement for th … 98 [OK]
ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 97 [OK]
We found a pile of mirrors here. Let's choose the one ranked No.1.
Now you need to download this image and use the following command:
sudo docker pull ubuntu:18.04
// Colon is behind the version number, do not know the words can only check online, do not write the words downloaded is the latest
But. It is said on the Internet that due to some force majeure, it is slow to download the mirror image in China, so it is necessary to add a mirror image. Need to add a file under the path of/etc/docker: daemon. json with the mirror address:
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
Then restart. Then execute the above command to download the mirror image, and then drink some coffee and wait for 1 time ~ ~ ~.
After downloading, let's look at what images are now on the computer and use the following command:
sudo docker images
// Results
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 18.04 7698f282e524 2 weeks ago 69.9MB
You can see here that there is already a mirror image of Ubuntu version 18.04. Now we need to start this image.
// Command
sudo docker run -it -d ubuntu:18.04 /bin/bash
// Explanation
run : Create 1 A new container and run 1 Commands
-it : Run the container in interactive mode , And reallocate 1 Pseudo input terminals, representing -i -t
--name ubuntu18: Specifies for the container 1 Names
-d : Background run container
ubuntu:18.04 : Mirror name
/bin/bash : Run the program in the mirror, if not, the mirror will stop directly
Now the mirror image has started successfully, but I have to log in. At this time, you need to see which containers are running now, executing:
// Command
sudo docker ps -a
// Explanation
ps : List containers
-a : Displays all containers, including those that are not running
// Results
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1ce6fa95862c ubuntu:18.04 "/bin/bash" 6 minutes ago Up 6 minutes brave_mendeleev
Here we can see that one container of NAME is brave_mendeleev in operation. Now let's go into this container. Execute the following command
// Command
sudo docker exec -it brave_mendeleev /bin/bash
// Explanation
brave_mendeleev: Container name
exec : Execute commands in running containers
// Results
hjx@hjx-PC:/etc/docker$ sudo docker exec -it brave_mendeleev /bin/bash
root@1ce6fa95862c:/#
In this way, we successfully logged into the container mirrored as ubuntu version 18.04. Now we can install mysql in it ~
Install mysql in the ubuntu container
Installing mysql I prefer to install it directly with apt myself. I'm typing directly here:
apt install mysql-server-5.7
It is found that it can be installed successfully in the container. After the installation is successful, we need to bind the mysql port in the container to port 3306 of our host. The steps here are:
1: Stop the container (don't stop it)
sudo service docker start
0
2: Submit the container with mysql installed as a new image
sudo service docker start
1
3: And bind the port and start the new image
Uh. . . Play here collapsed. . . It didn't work. /(o)/~ ~
I decided to bind port 3306 under 1 when I started the ubuntu image, and then perform the above operation again.
After a long operation. After deleting the original container, rebind port 3306 to start, log in to the container, and install mysql, it is perfectly installed and runs successfully.
A simpler way
Well, search for the mirror mysql directly, and then start it. It's as simple as that
sudo service docker start
2
After that, there are other 1 pile of parameters, which I don't need here, so I won't write it
Summarize