简体   繁体   English

Docker MySQL主机卷

[英]Docker MySQL Host Volume

I found that there is an official MySQL image for docker here . 我发现有对码头工人的MySQL官方图片在这里 Unfortunately, I am unable to start the container with a host volume. 不幸的是,我无法使用主机卷启动容器。 I have tried the following script. 我试过以下脚本。

DB_ROOT_PASS="myPassword"
DB_NAME="myDatabase"
DATA_DIR="$HOME/mysql_data"

mkdir -p $DATA_DIR
mkdir -p $DATA_DIR/conf.d

cd $DATA_DIR
wget -O my.cnf http://pastebin.com/raw.php?i=aV4pXRQD

sudo docker run \
-e MYSQL_ROOT_PASSWORD=$DB_ROOT_PASS \
-e MYSQL_DATABASE=$DB_NAME \
-p 3306:3306 \
-v $DATA_DIR:/etc/mysql \
mysql

which results in the following output: 这导致以下输出:

Running mysql_install_db ...
Installing MySQL system tables...2015-02-14 07:49:52 0 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
2015-02-14 07:49:52 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

Filling help tables...2015-02-14 07:49:55 0 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
2015-02-14 07:49:55 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/bin/mysqladmin -u root password 'new-password'
  /usr/bin/mysqladmin -u root -h 2efc65e86051 password 'new-password'

Alternatively you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /usr/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/mysql/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

Finished mysql_install_db
2015-02-14 07:49:57 0 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
2015-02-14 07:49:57 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

I have also tried without creating the conf.d directory or the my.cnf files which also result in other errors. 我也试过没有创建conf.d目录或my.cnf文件,这也导致其他错误。

Why is a volume necessary? 为什么需要一个卷?

A host volume provides "near metal" disk performance as well as data persistance which is important with a MySQL database. 主机卷提供“近金属”磁盘性能以及数据持久性,这对MySQL数据库很重要。 Thus backing up the data from the container, or using the "data container" pattern is not desired. 因此,不希望从容器备份数据,或使用“数据容器”模式。

Question: 题:

How can I update the script in order to start the Docker MySQL container with a host volume such that the MySQL service starts correctly? 如何更新脚本以启动具有主机卷的Docker MySQL容器,以便MySQL服务正确启动? Perhaps passing an init script or adding more data to the volume? 也许传递一个init脚本或向卷中添加更多数据?

Context 上下文

  • Ubuntu 14.04 64bit server Ubuntu 14.04 64位服务器
  • Docker version 1.5.0, build a8a31ef Docker版本1.5.0,构建a8a31ef

There were several problems, the primary one being that the original config file that was being downloaded had a bind-address setting that resulted in the mysql service not being able to be connected to from outside the host. 有几个问题,主要问题是正在下载的原始配置文件具有bind-address设置,导致mysql服务无法从主机外部连接。 I have since updated the setting (commented it out) and gotten the service running correctly, yet service mysql status still states MySQL Community Server 5.6.23 is not running. 我已经更新了设置(注释掉了)并使服务正常运行,但service mysql status仍然表明MySQL Community Server 5.6.23 is not running. even though it is. 即使它是。 I am 99% sure this is because of the "containerization" effect. 我99%肯定这是因为“集装箱化”效应。

Also, the data is not kept at /etc/mysql , so to achieve persistence and higher performance, we need to add another volume. 此外,数据不保存在/etc/mysql ,因此为了实现持久性和更高的性能,我们需要添加另一个卷。 The finalized working script is as such: 最终的工作脚本如下:

DB_ROOT_PASS="myPassword"
DB_NAME="myDatabase"
CONFIG_DIR="$HOME/mysql_config"
DATA_DIR="$HOME/mysql_data"

mkdir -p $DATA_DIR
mkdir -p $CONFIG_DIR
mkdir -p $CONFIG_DIR/conf.d

cd $CONFIG_DIR
sudo wget -O my.cnf http://pastebin.com/raw.php?i=aV4pXRQD

sudo docker run \
-e MYSQL_ROOT_PASSWORD=$DB_ROOT_PASS \
-e MYSQL_DATABASE=$DB_NAME \
-p 3306:3306 \
-v $CONFIG_DIR:/etc/mysql \
-v $DATA_DIR:/var/lib/mysql \
-d \
mysql

The reason you are seeing the message 你看到这条消息的原因

MySQL Community Server 5.6.23 is not running.

is because the command ps is not loaded in this container. 是因为命令ps未加载到此容器中。 The service mysql status command (and all of the service status commands) depend on ps to check status. service mysql status命令(以及所有服务状态命令)依赖于ps来检查状态。

When I run service mysql status the full message I get is: 当我运行service mysql status ,我得到的完整消息是:

/etc/init.d/mysql: line 41: ps: command not found
MySQL Community Server 5.6.23 is not running.

And indeed if I try running ps directly I get 事实上,如果我尝试直接运行ps,我会得到

bash: ps: command not found

Not certain why they did not provide ps in this container, might be worth opening an issue on it. 不确定为什么他们没有在这个容器中提供ps,可能值得在它上面打开一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM