离线安装docker docker-compose mysql镜像
一、下载docker docker-compose mysql 镜像文件
1、首先下载docker镜像
博主所用文件版本号: docker-23.0.6.tgz
下载docker 地址 :https://blog.csdn.net/xiaohanshasha/article/details/135489623?spm=1001.2014.3001.5501
2、下载docker-compose镜像
博主所用文件版本号: docker-compose-linux-x86_64
下载docker-compose 地址 :https://github.com/docker/compose/releases
3、Mysql镜像
博主所用文件版本号: mysql-5.7.38.tar
二、安装docker
1、将docker-23.0.6.tgz 文件上传到服务器上面
# 将 文件上传到 服务器/home/test下面
2、创建 docker.service文件
# 进入/etc/systemd/system ,创建 docker.service文件cd /etc/systemd/system
touch docker.service
将下方内容拷入 docker.service 文件中, :wq 保存
[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
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
3、安装docker (可查看下方图片)
# 进入docker文件所在目录
cd /home/test
# 解压:
tar -zxvf docker-23.0.6.tgz
# 解压完成后, 多了一个docker文件
# 将文件拷贝到/usr/bin/下面
cp docker/* /usr/bin/
# 赋予 docker.service 可执行权限
chmod +x /etc/systemd/system/docker.service
# 启动docker
systemctl daemon-reload
systemctl start docker
systemctl enable docker.service
# 查看docker 版本
docker -v
三、安装docker-compose
1、将docker-compose 镜像上传到服务器上,进入所在目录,执行下面操作
[root@localhost opt]# mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
[root@localhost opt]# chmod +x /usr/local/bin/docker-compose
[root@localhost opt]# docker-compose -v
Docker Compose version v2.5.0
# 能够 查看到版本号,既代表安装成功
四、安装mysql镜像
1、先将mysql-5.7.38.tar镜像上传到服务器上
2、进入mysql镜像所在位置,执行下面操作
# 加载离线镜像文件到本地仓库
docker load -i mysql-5.7.38.tar
# 查询是否加载成功,确保无误
docker images | grep mysql
3、配置docker-compose.yml文件(docker容器里面的目录请勿修改)
新建docker-compose.yml,将下方内容粘贴复制进去,记得修改端口号和密码
version: '3'
services:mysql:image: mysql:5.7.38restart: alwaysports:- 13306:3306networks:- front-msprivileged: truecontainer_name: mysqlenvironment:- "MYSQL_ROOT_PASSWORD=密码"#- "MYSQL_DATABASE=test"- "TZ=Asia/Shanghai"command:--default-time-zone='+8:00'--default-authentication-plugin=mysql_native_password--character-set-server=utf8mb4--collation-server=utf8mb4_general_ci--max_connections=1000--innodb_lock_wait_timeout=500volumes:# 映射地址,一定要在本地先新建这些文件- /etc/localtime:/etc/localtime:ro- ./mysql/data/:/var/lib/mysql/- ./mysql/conf/conf.d/:/etc/mysql/conf.d/- ./mysql/conf/my.cnf:/etc/mysql/my.cnf #sudo chmod 644 ./mysql/conf/my.cnf- ./mysql/logs/mysql.log:/logs/mysql.log# - ./mysql/init:/docker-entrypoint-initdb.d/networks:front-ms:driver: bridge
4、将mysql中的data、conf.d、my.cnf、mysql.log在本地新建
5、通过docker-compose构建mysql
#来到docker-compose文件目录下,执行构建mysql命令
docker-compose -f ./docker-compose.yml up mysql --build -d
#查询docker进程运行命令,状态为 up 即是正常运行
docker ps | grep mysql
五、使用网上随处可见的验证方法验证即可
1、使用navicat 测试连接
2、使用 docker exec -it 容器id bash
docker exec -it 容器id bashmysql -uroot -p 输入密码即可