Docker安裝常見應用記錄
阿新 • • 發佈:2020-08-24
Mysql
1.容器建立
docker run -d -p 3306:3306 --restart=always --privileged=true --env=MYSQL_ROOT_PASSWORD=admin --name=mysql -v E:/ForDocker/volume/mysql/conf:/etc/mysql/conf.d -v E:/ForDocker/volume/mysql/data:/var/lib/mysql -v E:/ForDocker/volume/mysql/log:/var/log/mysql mysql:5.7 --character-set-server=utf8 --collation-server=utf8_general_ci --default-authentication-plugin=mysql_native_password
2.引數解釋
--後臺執行,會返回容器ID
--宿主機對外暴露埠:容器內部埠
--設定開機啟動
--提升至進入容器擁有root許可權
--root使用者密碼
--應用別名
--掛載配置目錄
--掛載資料目錄
--掛載日誌目錄
映象名稱:映象標籤
--設定字符集為utf8
--設定字元比較規則為utf8_general_ci
--設定加密規則為mysql_native_password
3.亂碼問題
3.1 修改映象源
mv /etc/apt/sources.list /etc/apt/sources.list.bak
3.2 按照echo "xxx" >>/etc/apt/sources.list格式依次把xxx 替換為下面語句執行:
deb http://mirrors.163.com/debian/ buster main non-free contrib deb http://mirrors.163.com/debian/ buster-updates main non-free contrib deb http://mirrors.163.com/debian/ buster-backports main non-free contrib deb-src http://mirrors.163.com/debian/ buster main non-free contrib deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib deb-src http://mirrors.163.com/debian/ buster-backports main non-free contrib deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib deb-src http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
3.3 更新安裝源 apt-get update
3.4 安裝vim,然後編輯mysql配置檔案
3.5 也可以不安裝vim把容器配置檔案複製出來,改好再複製回去,然後重啟容器
vim /etc/mysql/mysql.conf.d/mysqld.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
3.6 推薦Dockefile快速構建
FROM mysql:5.7
MAINTAINER wuhui
#字符集
RUN echo "character-set-server=utf8" >> /etc/mysql/mysql.conf.d/mysqld.cnf \
&& echo "collation-server=utf8_general_ci" >> /etc/mysql/mysql.conf.d/mysqld.cnf \
#時區
&& echo "default-time-zone"='+8:00' \
&& echo "[client]" >> /etc/mysql/mysql.conf.d/mysqld.cnf \
&& echo "default-character-set=utf8" >> /etc/mysql/mysql.conf.d/mysqld.cnf \
&& echo "[mysql]" >> /etc/mysql/mysql.conf.d/mysqld.cnf \
&& echo "default-character-set=utf8" >> /etc/mysql/mysql.conf.d/mysqld.cnf \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
#時區
&& echo 'Asia/Shanghai' >/etc/timezone \
#解決5.7.5及以上預設啟用了ONLY_FULL_GROUP_BY模式,造成group by的問題
#1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
&& echo "[mysqld]" >> /etc/mysql/mysql.conf.d/mysqld.cnf \
&& echo "sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" >> /etc/mysql/mysql.conf.d/mysqld.cnf \
ENTRYPOINT ["/bin/bash"]
Redis
1. 下載配置檔案,稍作修改
http://download.redis.io/redis-stable/redis.conf
bind 127.0.0.1 #註釋掉這部分,這是限制redis只能本地訪問
protected-mode no #預設yes,開啟保護模式,限制為本地訪問
databases 16 #資料庫個數(可選),我修改了這個只是檢視是否生效。。
dir ./ #輸入本地redis資料庫存放資料夾(可選)
appendonly yes #redis持久化(可選)
2.生成容器
docker run --privileged=true -p 6379:6379 -v E:/ForDocker/volume/redis/data:/data -v E:/ForDocker/volume/redis/redis.conf:/etc/redis/redis.conf --name redis --restart=always -d redis redis-server /etc/redis/redis.conf --appendonly yes
3.進入redis
docker exec -ti redis redis-cli -h localhost -p 6379 或者 rdm客戶端直接連
RabitMQ
1.建立好宿主機檔案待掛載目錄
2.建立容器
docker run -d -p 15672:15672 -p 5672:5672 --name rabbitmq --privileged=true -v D:\ForDocker\volume\rabbitmq\conf:/etc/rabbitmq -v D:\ForDocker\volume\rabbitmq\data:/var/lib/rabbitmq/mnesia -v D:\ForDocker\volume\rabbitmq\log:/var/log/rabbitmq rabbitmq