In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
First create the build directory structure # mkdir-pv docker/mysql# cd docker/mysql/ second write Dockerfile file # vim Dockerfile # here sshd:latest is the mirror FROM sshd:latestMAINTAINER mykernel (www.mykernel.cn) # installation software RUN ENV DEBIAN_FRONTEND noninteractive apt-get update & &\ apt-get-yq install mysql-server-5.6 pwgen & &\ Rm-rf / var/lib/apt/lists/* # Delete the preinstalled database file RUN rm-rf / var/lib/mysql/* # add the MYSQL configuration file ADD my.cnf / etc/mysql/conf.d/my.cnf ADD mysqld_charset.cnf / etc/mysql/conf.d/mysqld_charset.cnf ADD authorized_keys / root/.ssh/authorized_ in the folder Keys # script for adding MYSQL ADD import_sql.sh / import_sql.sh ADD run.sh / run.shRUN chmod 755 / * .sh # sets environment variables User name and password ENV MYSQL_USER adminENV MYSQL_PASS * * Random** # set the environment variable ENV REPLICATION_MASTER * * False** ENV REPLICATION_SLAVE * * False** ENV REPLICATION_USER replica ENV REPLICATION_PASS replica # in master-slave replication mode and set the volumes that can be mounted Can be used to back up the database and configuration files VOLUME ["/ etc/mysql", "/ var/lib/mysql"] # set the port that can be mapped. If inherited from our sshd image, port 22 EXPOSE 3306 CMD ["/ run.sh"] will also be opened by default to prepare the ADD file # touch my.cnf mysqld_charset.cnf authorized_keys import_sql.sh run.sh needed in Dockefile.
(1) my.cnf is the main configuration file of mysql runtime, which needs to be written according to its own actual situation.
(2) mysqld_charset.cnf is configured for the characters of mysql runtime and needs to be written according to its own actual situation.
(3) import_sql.sh
(4) run.sh provides run files with master-slave copy and custom passwords here
Fourth, create an image # docker build-t mysql:first. Five tests # sudo docker run-d-p 1027 22-p 1026 3306-- name mysql mysql:first
Connect to the container through xshell to see whether the server is started. If you directly use the mysql command here, you can enter as root. After configuring the relevant users, close the container and submit it with docker commit.
Through the mysql default user name and user password remote connection mysqld test, the default user is admin password can be viewed using docker logs mysql. The admin user has all the privileges of root.
Note: every time you use the-P option to start the container, and then start the stop container each time, the port will change, so it is recommended to use-p to specify a fixed port. You can reduce the modification of iptables rules or the security policy of CVM
Six mount mysql data volume # docker run-d-P-v / mydata/mysql:/var/lib/mysql mysql:first
In fact, the VOLUME directive has been used in mysql's dockerfile file to create a space that is always valid for the container (it will not be deleted because the container is deleted), but this space is newly created and the commands on the physical machine are more complex. You can directly use the-v option to mount a host's current directory, and the container can directly access all the data in that directory.
7. Set the password of the mysql default user
The default mysql password uses docker logs | View after starting the container. Change the password of the default user (admin):
# docker run-d-P-e MYSQL_PASS= "your_pass" mysql:first
The-e parameter can be used to set any environment variable in the container. It even overrides existing environment variables, or environment variables set through ENV in Dockerfile.
8 enable master-slave mode
Create the mysql master container
# docker run-d-e REPLICATION_MASTER=true-P-name mysql:first
Create a mysql slave container (- link name:alias)
# docker run-d-e REPLICATION_SLAVE=true-- link mysql:mysql mysql:first
Note: the-name of the main container here must be mysql, otherwise an error will be reported.
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.