# 1、启动mysql镜像
docker run -d -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD="secret" -e MYSQL_DATABASE=redmine mysql:5.7
如果本地仓库没有MySQL镜像,docker将自动拉去官方仓库拉去,如下图:
# 2、 修改mysql配置(主要修改utf-8字符集)
参考资料:http://blog.csdn.net/sqandczm/article/details/78152451?locationNum=7&fps=1
docker exec -it cee6 /bin/bash # 进入容器
mysql -u root -p # 登录数据库,密码:secset
SHOW VARIABLES LIKE 'character_set_%'; # 查看数据库字符集
SHOW VARIABLES LIKE 'collation_%';
SET NAMES 'utf8';
最后修改/etc/mysql/mysql.conf.d/mysql.cnf配置文件,内容如下所示(黄底字体部分):
~~~bash
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysql]
default-character-set = utf8
[mysql_safe]
default-character-set = utf8
[client]
default-character-set = utf8
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
init_connect = 'SET NAMES utf8'
character-set-server = utf8
collation-server = utf8_unicode_ci
~~~
exit退出数据库
vim /etc/mysql/mysql.conf.d/mysqld.cnf 报错,
因为镜像中没有安装vim,所以需要安装vim
通过查看官方dockerfile文件得知mysql官方镜像的基础镜像是debian ,所以安装vim的命令是:
Apt-get install -y vim
接着会报错 E: Unable to locate package vim
究其原因,应该是镜像刚运行,软件源还来不及更新,所以才会无法找到包。
这时候需要敲:apt-get update
这个命令的作用是:同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。
等更新完毕以后再敲命令:apt-get install -y vim命令即可,现在可以使用vim了。
vim /etc/mysql/mysql.conf.d/mysqld.cnf
保存退出后,exit退出容器,docker restart 重启容器
**注:修改配置文件后退出并重启mysql服务(通过docker restart命令);另本步骤为必须,否则redmine将无法正确保存中文,会报异常无法操作。**
完成MySQL配置后,将容器打包成新的镜像,以后再部署redmine的MySQL服务器就可以直接使用新镜像了
docker commit cee mysql-with-vim
# 3、 docker下拉取并启动redmine镜像
docker run -d -p 8088:3000 --name some-redmine --link some-mysql:mysql redmine:3.4
# 4、 访问Redmine打开浏览器访问物理机的8088端口就可以打开redmine的页面了。管理员帐号是admin,密码admin