docker創建mysql容器,並掛載數據+配置

新建:/my/mysql/my.cnf (準備掛載配置文件用)

將以下內容拷貝進去(或者啓動一個docker的mysql,並且把/etc/mysql/my.cnf中的內容拷貝出來)

# Copyright (c) 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

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

[mysqld]
sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
lower_case_table_names=0

運行如下命令

docker run --privileged=true --name mysql5.7 -p 3306:3306 
-v /my/mysql/datadir:/var/lib/mysql 
-v /my/mysql/conf.d:/etc/mysql/conf.d 
-v /my/mysql/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=yourpassword -d mysql:5.7

下面這兩行配置是掛載數據

-v /my/mysql/datadir:/var/lib/mysql
-v /my/mysql/conf.d:/etc/mysql/conf.d

掛載mysql配置文件
-v /my/mysql/my.cnf:/etc/mysql/my.cnf

啓動後修改/my/mysql/my.cnf並重啓docker對應mysql容器即可生效配置

docker ps #找到對應容器ID
#重啓容器
docker stop 3
docker start 3

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章