离线环境安装docker、mysql、redis、nginx
生成镜像
1.在联网的Linux系统上拉取镜像
#拉取mysql5.7版本
docker pull mysql:5.7
2.执行导出命令
#查看镜像
docker images
#导出镜像到root目录下,mysql_57.gz为导出的文件名称,后面的mysql是镜像名称
docker save -o mysql_57.gz mysql
3.将生成的文件导入到离线Linux系统
离线安装docker
1.docker下载
云盘下载docker
2.解压
#解压
tar -zxvf docker-18.03.1-ce.tgz
#将解压出来的docker文件内容移动到 /usr/bin/ 目录下
cp docker/* /usr/bin/
#将docker注册为service
vim /etc/systemd/system/docker.service
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
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
chmod +x /etc/systemd/system/docker.service
#重新加载配置文件
systemctl daemon-reload
#启动docker
systemctl start docker
#设置开机自启
systemctl enable docker.service
#验证
#查看版本
docker version
#查看状态
systemctl status docker
docker离线安装mysql
1. 加载镜像
#加载mysql镜像
docker load -i mysql_57.gz
#验证
docker images
2.启动
#启动mysql
#docker run -d -p 3306:3306 --name mymysql -e MYSQL_ROOT_PASSWORD=自己设置的密码 镜像名称:版本号
docker run -d -p 3306:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:5.7
#进入mysql容器内部 docker exec -it 容器id /bin/sh
docker exec -it 478900fd13aa /bin/sh
#修改远程权限alter user 'root'@'%' identified with mysql_native_password by 'root';
#启动redis
docker run -itd --name redis-test -p 6379:6379 redis
#进入redis
docker exec -it redis-test /bin/bash
#启动nginx
docker run --name nginx -d -p 80:80 --restart=always --privileged=true -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/log:/var/log/nginx nginx