日常学习记录,有错误欢迎留言指导,谢谢
将文件上传到系统/data/docker上 如果没有则手动创建
mkdir /data/docker
cd /data/docker
tar -zxvf docker-xxx.tgz
cp docker/* /usr/bin/
cd /etc/systemd/system/ touch docker.service
vi docker.service
并将以下内容添加到文件中
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=xxx ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. # TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target
第11行的insecure-registry=xxx,根据实际情况改为本机ip
chmod 777 /etc/systemd/system/docker.service
systemctl start docker systemctl enable docker.service # 设置开机启动 systemctl status docker # 查看docker状态
出现以下界面则docker安装成功
cp docker-compose-xxx /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
出现下面结果则表示安装成功
docker pull mysql:8.0.36
或者直接上传其他系统打包好的镜像包
mkdir -p /data/mysql-qzk01/log mkdir -p /data/mysql-qzk01/data mkdir -p /data/mysql-qzk01/conf.d
vi /data/mysql-qzk01/conf.d/my.cnf
这里需要给MySQL做点自定义的配置,比如时区字符编码等。
###### [client]配置模块 ###### [client] default-character-set=utf8mb4 socket=/var/lib/mysql/mysql.sock ###### [mysql]配置模块 ###### [mysql] # 设置MySQL客户端默认字符集 default-character-set=utf8mb4 socket=/var/lib/mysql/mysql.sock ###### [mysqld]配置模块 ###### [mysqld] port=3306 user=mysql # 设置sql模式 sql_mode模式引起的分组查询出现*this is incompatible with sql_mode=only_full_group_by,这里最好剔除ONLY_FULL_GROUP_BY sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock server-id = 1 # MySQL8 的密码认证插件 如果不设置低版本navicat无法连接 default_authentication_plugin=mysql_native_password # 禁用符号链接以防止各种安全风险 symbolic-links=0 # 允许最大连接数 max_connections=1000 # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8mb4 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB # 表名存储在磁盘是小写的,但是比较的时候是不区分大小写 lower_case_table_names=1 max_allowed_packet=16M # 设置时区 default-time_zone='+8:00'
version: '3' services: mysql-qzk01: # 服务名称 建议与容器名称一致 image: mysql:8.0.36 # 当前数据库的版本 container_name: mysql-qzk01 # 容器名称 environment: - MYSQL_ROOT_PASSWORD=123456 # root用户密码 # - TZ=Asia/Shanghai # 设置容器时区 我这里通过下面挂载方式同步的宿主机时区和时间了,这里忽略 volumes: - /data/mysql-qzk01/log:/var/log/mysql # 映射日志目录,宿主机:容器 - /data/mysql-qzk01/data:/var/lib/mysql # 映射数据目录,宿主机:容器 - /data/mysql-qzk01/conf.d:/etc/mysql/conf.d # 映射配置目录,宿主机:容器 - /etc/localtime:/etc/localtime:ro # 让容器的时钟与宿主机时钟同步,避免时间的问题,ro是read only的意思,就是只读。 ports: - 3307:3306 # 指定宿主机端口与容器端口映射关系,宿主机:容器,宿主机ip根据使用情况进行修改 restart: always # 容器随docker启动自启
cd /data/mysql-qzk01/ # 进入到docker-compose.yml对应的容器文件夹下
docker-compose -f docker-compose.yml up -d
如果需要停止容器或者重启容器的话
这就是服务名称与容器名称一致的好处
docker-compose stop mysql-qzk01 # 停止指定服务容器 docker-compose restart mysql-qzk01 # 重启指定服务容器
docker ps -a
docker exec -it 容器ID/容器名称 /bin/bash # 进入docker容器 mysql -h127.0.0.1 -uroot -p123456 # 登录mysql
上一篇:Golang函数和包