由host网络改成main网络,重新定义service脚本和nginx脚本
This commit is contained in:
parent
f2d14ffc29
commit
ec3e21b882
@ -1,19 +1,28 @@
|
||||
name: nginx
|
||||
networks:
|
||||
main: # 定义一个外部网络
|
||||
external: true
|
||||
|
||||
services:
|
||||
nginx:
|
||||
image: quay.io/wandoubaba517/nginx:1.27
|
||||
container_name: nginx
|
||||
restart: always
|
||||
volumes:
|
||||
- ./conf/nginx.conf:/etc/nginx/nginx.conf
|
||||
- ./conf/conf.d:/etc/nginx/conf.d
|
||||
- ./conf/certs:/etc/nginx/certs
|
||||
- ./conf/fastcgi_params:/etc/nginx/fastcgi_params
|
||||
- ./conf/mime.types:/etc/nginx/mime.types
|
||||
- ./conf/scgi_params:/etc/nginx/scgi_params
|
||||
- ./conf/uwsgi_params:/etc/nginx/uwsgi_params
|
||||
- ./html:/usr/share/nginx/html
|
||||
working_dir: /usr/share/nginx/html
|
||||
services:
|
||||
nginx:
|
||||
image: quay.io/wandoubaba517/nginx:1.27
|
||||
container_name: nginx
|
||||
restart: always
|
||||
volumes:
|
||||
- ./conf/nginx.conf:/etc/nginx/nginx.conf
|
||||
- ./conf/conf.d:/etc/nginx/conf.d
|
||||
- ./conf/certs:/etc/nginx/certs
|
||||
- ./conf/fastcgi_params:/etc/nginx/fastcgi_params
|
||||
- ./conf/mime.types:/etc/nginx/mime.types
|
||||
- ./conf/scgi_params:/etc/nginx/scgi_params
|
||||
- ./conf/uwsgi_params:/etc/nginx/uwsgi_params
|
||||
- ./html:/usr/share/nginx/html
|
||||
working_dir: /usr/share/nginx/html
|
||||
stdin_open: true
|
||||
network_mode: host
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
networks:
|
||||
main:
|
||||
ipv4_address: 192.168.250.250 # 指定容器的 IP 地址
|
||||
aliases:
|
||||
- nginx # 设置别名
|
17
service
17
service
@ -1,17 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
container_name="nginx"
|
||||
|
||||
if [ "$1" = "start" ]; then
|
||||
docker compose up -d
|
||||
elif [ "$1" = "stop" ]; then
|
||||
docker compose down
|
||||
elif [ "$1" = "restart" ]; then
|
||||
docker restart $container_name
|
||||
elif [ "$1" = "reload" ]; then
|
||||
docker exec -i $container_name service nginx reload
|
||||
elif [ "$1" = "status" ]; then
|
||||
docker exec -i $container_name service nginx status
|
||||
else
|
||||
echo "Usage: $0 [start|stop|restart|reload|status]"
|
||||
fi
|
42
service.sh
Executable file
42
service.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
container_name="nginx"
|
||||
network_name="main"
|
||||
subnet="192.168.250.0/24"
|
||||
|
||||
# 检查网络是否存在
|
||||
function network_check {
|
||||
if ! docker network ls | grep -w "$network_name" > /dev/null 2>&1; then
|
||||
echo "Network $network_name does not exist. Creating it..."
|
||||
docker network create --subnet="$subnet" "$network_name"
|
||||
fi
|
||||
}
|
||||
|
||||
# 启动服务
|
||||
function start {
|
||||
network_check # 检查并创建网络(如有必要)
|
||||
docker compose up -d # 启动服务
|
||||
}
|
||||
|
||||
# 处理脚本参数
|
||||
case "$1" in
|
||||
start)
|
||||
start # 调用 start 函数
|
||||
;;
|
||||
stop)
|
||||
docker compose down # 停止服务
|
||||
;;
|
||||
restart)
|
||||
docker compose down # 停止服务
|
||||
start # 启动服务
|
||||
;;
|
||||
reload)
|
||||
docker exec -i "$container_name" service nginx reload # 重载 Nginx 配置
|
||||
;;
|
||||
status)
|
||||
docker exec -i "$container_name" service nginx status # 查看 Nginx 状态
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 [start|stop|restart|reload|status]" # 打印用法信息
|
||||
;;
|
||||
esac
|
Loading…
Reference in New Issue
Block a user