In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the detailed steps of installing MySQL in Docker". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the detailed steps of installing MySQL in Docker.
Docker installation MySQL method 1. Docker pull mysql
Find the mysql image on Docker Hub
Runoob@runoob:/mysql$ docker search mysqlNAME DESCRIPTION STARS OFFICIAL AUTOMATEDmysql MySQL is a widely used, open-source relati... 2529 [OK] mysql/mysql-server Optimized MySQL Server Docker images. Crea... 161 [OK] centurylink/mysql Image containing mysql. Optimized to be li... 45 [OK] sameersbn/mysql 36 [OK] google/mysql MySQL server for Google Compute Engine 16 [OK] appcontainers/mysql Centos/Debian Based Customizable MySQL Con... 8 [OK] marvambass/mysql MySQL Server based on Ubuntu 14.04 6 [OK] drupaldocker/mysql MySQL for Drupal 2 [OK] azukiapp/mysql Docker image to run MySQL by Azuki-http:... 2 [OK].
Here we pull the official image, labeled 5.6
Runoob@runoob:~/mysql$ docker pull mysql:5.6
After waiting for the download to be completed, we can look up the image with REPOSITORY mysql and label 5.6 in the local image list.
Runoob@runoob:~/mysql$ docker images | grep mysqlmysql 5.6 2c0964ec182a 3 weeks ago 329 MB method 2. Build through Dockerfile
Create Dockerfile
First, create the directory mysql, which will be used to store the following related things.
Runoob@runoob:~$ mkdir-p ~ / mysql/data ~ / mysql/logs ~ / mysql/conf
The data directory will map to the data file storage path configured by the mysql container
The logs directory will map to the log directory of the mysql container
The configuration file in the conf directory will be mapped to the configuration file of the mysql container
Enter the created mysql directory and create the Dockerfile
FROM debian:jessie# add our user and group first to make sure their IDs get assigned consistently Regardless of whatever dependencies get addedRUN groupadd-r mysql & & useradd-r-g mysql mysql# add gosu for easy step-down from rootENV GOSU_VERSION 1.7RUN set-x\ & & apt-get update & & apt-get install- y-- no-install-recommends ca-certificates wget & & rm-rf / var/lib/apt/lists/*\ & & wget-O / usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu -$(dpkg-- print-architecture) "\ & & wget-O / usr/local/bin/gosu.asc" https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg-- print-architecture) .ASC "\ & & export GNUPGHOME=" $(mktemp-d) "\ & & gpg-- keyserver ha.pool.sks-keyservers.net-- recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4\ & & gpg-- batch-- verify / usr / local/bin/gosu.asc / usr/local/bin/gosu\ & & rm-r "$GNUPGHOME" / usr/local/bin/gosu.asc\ & & chmod + x / usr/local/bin/gosu\ & & gosu nobody true\ & & apt-get purge-y-- auto-remove ca-certificates wgetRUN mkdir / docker-entrypoint-initdb.d# FATAL ERROR: please install the following Perl modules before executing / usr/local/mysql/scripts/mysql_install_db:# File: Basename# File::Copy# Sys::Hostname# Data::DumperRUN apt-get update & & apt-get install- y perl pwgen-- no-install-recommends & & rm-rf / var/lib/apt/lists/*# gpg: key 5072E1F5: public key "MySQL Release Engineering" importedRUN apt-key adv-- keyserver ha.pool.sks-keyservers.net-- recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5ENV MYSQL_MAJOR 5.6ENV MYSQL_VERSION 5.6.31-1debian8RUN echo "deb http://repo.mysql.com/apt/ Debian/ jessie mysql-$ {MYSQL_MAJOR} "> / etc/apt/sources.list.d/mysql.list# the" / var/lib/mysql "stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already" configured "(ie Stuff in / var/lib/mysql/mysql) # also, we set debconf keys to make APT a little quieterRUN {\ echo mysql-community-server mysql-community-server/data-dir select' \ echo mysql-community-server mysql-community-server/root-pass password';\ echo mysql-community-server mysql-community-server/re-root-pass password';\ echo mysql-community-server mysql-community-server/remove-test-db select false | debconf-set-selections\ & & apt-get update & & apt-get install-y mysql-server= "${MYSQL_VERSION}" & & rm-rf / var/lib/apt/lists/*\ & & rm-rf / var/lib/mysql & & mkdir-p / var/lib/mysql / var/run/mysqld\ & & chown-R mysql:mysql / var/lib/mysql / var/run/mysqld\ # ensure that / var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime & & chmod 777 / var/run/mysqld# comment out a few problematic configuration values# don't reverse lookup hostnames They are usually another containerRUN sed-Ei's / ^ (bind-address | log) / # & /'/ etc/mysql/my.cnf\ & & echo 'skip-host-cache\ nskip-name-resolve' | awk' {print} $1 = "[mysqld]" & & c = = 0 {c = 1 System ("cat")}'/ etc/mysql/my.cnf > / tmp/my.cnf\ & & mv / tmp/my.cnf / etc/mysql/my.cnfVOLUME / var/lib/mysqlCOPY docker-entrypoint.sh / usr/local/bin/RUN ln-s usr/local/bin/docker-entrypoint.sh / entrypoint.sh # backwards compatENTRYPOINT ["docker-entrypoint.sh"] EXPOSE 3306CMD ["mysqld"]
Create an image through Dockerfile and replace it with your own name
Runoob@runoob:~/mysql$ docker build-t mysql.
After the creation is completed, we can find the image we just created in the local image list.
Runoob@runoob:~/mysql$ docker images | grep mysqlmysql 5.6 2c0964ec182a 3 weeks ago 329 MB uses mysql image to run container runoob@runoob:~/mysql$ docker run-p 3306 MYSQL_ROOT_PASSWORD=123456 3306-- name mymysql-v $PWD/conf:/etc/mysql/conf.d-v $PWD/logs:/logs-v $PWD/data:/var/lib/mysql-e MYSQL_ROOT_PASSWORD=123456-d mysql:5.621cb89213c93d805c5bacf1028a0da7b5c5852761ba81327e6b99bb3ea89930erunoob@runoob:~/mysql$
Command description:
-p 3306virtual 3306: map port 3306 of the container to port 3306 of the host.
-v $PWD/conf:/etc/mysql/conf.d: Mount the conf/my.cnf under the current directory of the host to the / etc/mysql/my.cnf of the container.
-v $PWD/logs:/logs: Mount the logs directory under the current directory of the host to the / logs of the container.
-v $PWD/data:/var/lib/mysql: Mount the data directory under the current directory of the host to the / var/lib/mysql of the container.
-e MYSQL_ROOT_PASSWORD=123456: initializes the password of the root user.
Check the container startup status runoob@runoob:~/mysql$ docker ps CONTAINER ID IMAGE COMMAND... PORTS NAMES21cb89213c93 mysql:5.6 "docker-entrypoint.sh"... 0.0.0.014 3306-> 3306/tcp mymysql
Docker install PHP
Docker install Tomcat
2 notes to write notes
Brian
153***2799@qq.com
0
The docker image of the latest official MySQL (5.7.19) is mapped in a different profile directory when it is created. Record it here and share it with you:
Official original text:
The MySQL startup configuration is specified in the file / etc/mysql/my.cnf, and that file in turn includes any files found in the / etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in / etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as / etc/mysql/conf.d inside the mysql container.
It probably means:
The default configuration file for MySQL (5.7.19) is the / etc/mysql/my.cnf file. If you want to customize the configuration, it is recommended that you create a .cnf file in the / etc/mysql/conf.d directory. The newly created file can be named anything, as long as the suffix is cnf. Configuration items in the newly created file can overwrite configuration items in / etc/mysql/my.cnf.
Specific operations:
You first need to create the directory and .cnf file that will be mapped to the container, and then create the container
# pwd/opt# mkdir-p docker_v/mysql/conf# cd docker_v/mysql/conf# touch my.cnf# docker run-p 3306 name mysql-v / opt/docker_v/mysql/conf:/etc/mysql/conf.d-e MYSQL_ROOT_PASSWORD=123456-d imageID4ec4f56455ea2d6d7251a05b7f308e314051fdad2c26bf3d0f27a9b0c0a71414
Command description:
Check the container operation
# docker psCONTAINER ID IMAGE COMMAND... PORTS NAMES4ec4f56455ea c73c7527c03a "docker-entrypoint.sh"... 0.0.0.014 3306-> 3306/tcp mysql
Brian
Brian
153***2799@qq.com
2 years ago (2017-09-08)
-p 3306virtual 3306: map port 3306 of the container to port 3306 of the host
-v / opt/docker_v/mysql/conf:/etc/mysql/conf.d: Mount the host / opt/docker_v/mysql/conf directory to the container's / etc/mysql/conf.d
-e MYSQL_ROOT_PASSWORD=123456: initializes the password of the root user
-d: runs the container in the background and returns the container ID
ImageID: mysql image ID
Liaozesong
Lia***song@yeah.net
Reference address
0
Docker installs mysql 8 version
Download mysqldocker pull mysql# from # docker to launch docker run-- name mysql-p 3306 name mysql-e MYSQL_ROOT_PASSWORD=Lzslov123!-d mysql# enter the container docker exec-it mysql bash# to log in to mysqlmysql-u root-pALTER USER 'root'@'localhost' IDENTIFIED BY' Lzslov123 remote login # add a remote login user CREATE USER 'liaozesong'@'%' IDENTIFIED WITH mysql_native_password BY' Lzslov123 remote login to enable Grant ALL PRIVILEGES ON *. * TO 'liaozesong'@'%'
At this point, I believe you have a deeper understanding of the "detailed steps for Docker to install MySQL". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.