1、安装docker
参考:https://www.runoob.com/docker/centos-docker-install.html
# 删除旧的docker
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 安装yum
sudo yum install -y yum-utils
#配置阿里docker镜像
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装docker
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 启动docker
sudo systemctl start docker
# 停止docker
sudo systemctl stop docker
# 重启docker
sudo systemctl restart docker
# 系统启动时自运行docker
sudo systemctl enable docker
# 检查docker状态
sudo systemctl status docker
#docker hello world
sudo docker run hello-world
# docker镜像加速器
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
# docker命令
docker ps #查看docker容器
docker images #查看docker镜像
docker logs -f 容器名 #打印日志
docker search 镜像名 #查找镜像
docker exec -it 容器名 /bin/sh #进入容器
2、docker部署nginx
参考:https://blog.csdn.net/weixin_45481821/article/details/134564864
# 创建文件夹
# 静态文件反向代理
mkdir -p /home/static
# 前端文件夹
mkdir -p /home/项目名/dist
# ssl证书文件夹
mkdir -p /home/nginx/ssl
# 上传nginx.conf到/home/nginx/下
# 复制docker配置文件到/home/nginx/conf.d
# 上传ssl证书到/home/nginx/ssl下
#docker cp nginx:/etc/nginx/nginx.conf /home/nginx/nginx-origin.conf
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf.d
# /home/nginx 为挂载的基本目录
# docker运行
docker run \
-p 80:80 \
-p 8099:8099 \
-p 443:443 \
--name mynginx \
-v /home/static/:/home/static \
-v /home/项目名/dist:/home/项目名/dist \
-v /home/nginx/conf.d:/etc/nginx/conf.d \
-v /home/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/logs:/var/log/nginx \
-v /home/nginx/ssl:/usr/local/nginx/ssl \
-d nginx:lastest
#查看端口是否已启动:
netstat -anp|grep 80
3、yum部署nginx
# yum安装nginx
yum install -y nginx
# 查看nginx版本
nginx -v
# 上传nginx.conf到/etc/nginx/下
# 上传ssl证书到/home/nginx/ssl下
# 或者手动修改nginx配置文件
#vim /etc/nginx/nginx.conf
# 启动nginx
systemctl start nginx
systemctl stop nginx
systemctl status nginx
systemctl restart nginx
#查看端口是否已启动:
netstat -anp|grep 80
4、安装包方式部署nginx
# 以/usr/local/nginx作为基本路径
mkdir -p /usr/local/nginx
cd /usr/local/nginx
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1
# 编译
./configure --with-http_ssl_module --with-stream
# 安装
make && make install
# 上传nginx.conf到/usr/local/nginx/conf/下
# 上传ssl证书到/home/nginx/ssl下
# 或者手动修改nginx配置文件
#vim /usr/local/nginx/conf/nginx.conf
# 启动nginx
cd /usr/local/nginx/sbin
./nginx
# 停止
./nginx -s stop
# 重启
./nginx -s reload
# 查看版本
./nginx -v
#查看端口是否已启动:
netstat -anp|grep 80