#!/bin/bash
nginx_port=9080
if [ "$#" -eq 0 ]; then
echo "default nginx port: $nginx_port"
else
nginx_port="$1"
echo "set nginx port: $nginx_port"
fi
docker rm nginx
# 1.拉一个镜像拿到基础文件与配置
docker pull nginx
mkdir -p /mydata/nginx/conf
touch /mydata/nginx/conf/nginx.conf
mkdir -p /mydata/nginx/log
mkdir -p /mydata/nginx/html
docker run --name nginx -p $nginx_port:80 -d nginx
docker cp nginx:/etc/nginx/nginx.conf /mydata/nginx/conf/nginx.conf
docker cp nginx:/etc/nginx/conf.d /mydata/nginx/conf/conf.d
docker cp nginx:/usr/share/nginx/html /mydata/nginx/
docker rm -f nginx
# 2.通过之前拿到的基础文件 运行容器并且挂上数据卷(数据卷依次是:配置文件、配置文件目录、日志目录、静态文件目录)
docker run \
-p $nginx_port:80 \
--name nginx \
-v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /mydata/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /mydata/nginx/log:/var/log/nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-d nginx:latest
echo "install finish run 'docker ps' and access localhost:${nginx_port} to check!"
docker 安装 nginx 脚本
最新推荐文章于 2024-08-21 10:42:01 发布